github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/pkg/mail/mail.go (about)

     1  package mail
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/cozy/gomail"
     7  )
     8  
     9  const (
    10  	// ModeFromStack is the no-reply mode of a mail, to send mail "to" the
    11  	// user's mail, as a noreply@
    12  	ModeFromStack = "noreply"
    13  	// ModePendingEmail is used to send an email to confirm the new email
    14  	// address of the user
    15  	ModePendingEmail = "pending"
    16  	// ModeFromUser is the "from" mode of a mail, to send mail "from" the user's
    17  	// mail.
    18  	ModeFromUser = "from"
    19  	// ModeSupport is used to send both a request to the support and a
    20  	// confirmation to the user.
    21  	ModeSupport = "support"
    22  	// ModeCampaign is used to send a non transactional email to the user
    23  	ModeCampaign = "campaign"
    24  
    25  	// DefaultLayout defines the default MJML layout to use
    26  	DefaultLayout = "layout"
    27  	// CozyCloudLayout defines the alternative MJML layout
    28  	CozyCloudLayout = "layout-cozycloud"
    29  )
    30  
    31  // Address contains the name and mail of a mail recipient.
    32  type Address struct {
    33  	Name  string `json:"name"`
    34  	Email string `json:"email"`
    35  }
    36  
    37  // Attachment is for attaching a file to the mail
    38  type Attachment struct {
    39  	Filename string `json:"filename"`
    40  	Content  []byte `json:"content"`
    41  }
    42  
    43  // Options should be used as the options of a mail with manually defined
    44  // content: body and body content-type. It is used as the input of the
    45  // "sendmail" worker.
    46  type Options struct {
    47  	Mode           string                 `json:"mode"`
    48  	Subject        string                 `json:"subject"`
    49  	From           *Address               `json:"from,omitempty"`
    50  	To             []*Address             `json:"to,omitempty"`
    51  	ReplyTo        *Address               `json:"reply_to,omitempty"`
    52  	Dialer         *gomail.DialerOptions  `json:"dialer,omitempty"`
    53  	Date           *time.Time             `json:"date,omitempty"`
    54  	Parts          []*Part                `json:"parts,omitempty"`
    55  	RecipientName  string                 `json:"recipient_name,omitempty"`
    56  	TemplateName   string                 `json:"template_name,omitempty"`
    57  	TemplateValues map[string]interface{} `json:"template_values,omitempty"`
    58  	Attachments    []*Attachment          `json:"attachments,omitempty"`
    59  	Locale         string                 `json:"locale,omitempty"`
    60  	Layout         string                 `json:"layout,omitempty"`
    61  }
    62  
    63  // Part represent a part of the content of the mail. It has a type
    64  // specifying the content type of the part, and a body.
    65  type Part struct {
    66  	Type string `json:"type"`
    67  	Body string `json:"body"`
    68  }