本文整理汇总了Golang中net/mail.Address类的典型用法代码示例。如果您正苦于以下问题:Golang Address类的具体用法?Golang Address怎么用?Golang Address使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Address类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewMessage
func NewMessage(from, to *mail.Address, subject string, files []string, templatePath,
htmlTemplatePath string, context interface{}) (*email.Email, error) {
msg := &email.Email{
From: from.String(),
To: []string{to.String()},
Subject: subject,
}
for _, file := range files {
_, err := msg.AttachFile(file)
if err != nil {
return nil, err
}
}
if templatePath != "" {
parsed, err := parseTemplate(templatePath, context)
if err != nil {
return nil, err
}
msg.Text = parsed
}
if htmlTemplatePath != "" {
parsed, err := parseTemplate(htmlTemplatePath, context)
if err != nil {
return nil, err
}
msg.HTML = parsed
}
return msg, nil
}
示例2: RequestPasswordReminder
// RequestPasswordReminder requests JustGiving to send a password reset email
func (svc *Service) RequestPasswordReminder(account mail.Address) error {
method := "GET"
// mail.Address stores email in the format <[email protected]>, we don't want the `<` `>`
em := account.String()
em = em[1 : len(em)-1]
path := bytes.NewBuffer([]byte(svc.BasePath))
path.WriteString("/")
path.WriteString(svc.APIKey)
path.WriteString("/v1/account/")
path.WriteString(em)
path.WriteString("/requestpasswordreminder")
req, err := api.BuildRequest(UserAgent, ContentType, method, path.String(), nil)
if err != nil {
return err
}
res, _, err := api.Do(svc.client, svc.origin, "RequestPasswordReminder", req, "", svc.HTTPLogger)
if err != nil {
return err
}
if res.StatusCode != 200 {
return fmt.Errorf("invalid response %s", res.Status)
}
return nil
}
示例3: AddRecipient
// AddRecipient will add mail.Address emails to recipients.
func (m *SGMail) AddRecipient(recipient *mail.Address) {
m.SMTPAPIHeader.AddTo(recipient.String())
m.To = append(m.To, recipient.Address)
if recipient.Name != "" {
m.ToName = append(m.ToName, recipient.Name)
}
}
示例4: sendEmail
func sendEmail(senderFunc mailSender, smtpConfig smtpConfiguration, ts time.Time, errors []verificationError) error {
// set up possible authentication
var auth smtp.Auth
if smtpConfig.Auth != nil {
a := *smtpConfig.Auth
auth = smtp.PlainAuth(
"",
a.Username,
a.Password,
smtpConfig.Host,
)
} else {
auth = nil
}
from := mail.Address{Address: smtpConfig.From}
toString := makeToAddresses(smtpConfig.To)
title := "Ismonitor alert"
body := makeMessage(errors)
message := makeHeaders(from.String(), toString, title, ts) // headers
message += "\r\n"
message += base64.StdEncoding.EncodeToString([]byte(body)) // body
return senderFunc(
smtpConfig.Host+":"+fmt.Sprintf("%d", smtpConfig.Port),
auth,
from.Address,
smtpConfig.To,
[]byte(message))
}
示例5: FundraisingPagesForCharityAndUser
// FundraisingPagesForCharityAndUser returns the charity's fundraising pages registered with the specified JustGiving user account
func (svc *Service) FundraisingPagesForCharityAndUser(charityID uint, account mail.Address) ([]*FundraisingPageRef, error) {
var results []*FundraisingPageRef
// mail.Address stores email in the format <[email protected]>, this simply removes the `<` `>`
em := account.String()
if em != "" {
em = em[1 : len(em)-1]
}
method := "GET"
path := bytes.NewBuffer([]byte(svc.BasePath))
path.WriteString("/")
path.WriteString(svc.APIKey)
path.WriteString("/v1/account/")
path.WriteString(em)
path.WriteString("/pages/?charityId=")
path.WriteString(strconv.FormatUint(uint64(charityID), 10))
req, err := api.BuildRequest(UserAgent, ContentType, method, path.String(), nil)
if err != nil {
return nil, err
}
res, resBody, err := api.Do(svc.client, svc.origin, "FundraisingPagesForCharityAndUser", req, "", svc.HTTPLogger)
if err != nil {
return nil, err
}
if res.StatusCode == 404 {
return results, nil
}
if res.StatusCode != 200 {
return nil, fmt.Errorf("invalid response %s", res.Status)
}
var result = []struct {
EventID uint `json:"eventId"`
PageID uint `json:"pageId"`
PageShortName string `json:"pageShortName"`
}{}
if err := json.Unmarshal([]byte(resBody), &result); err != nil {
return nil, fmt.Errorf("invalid response %v", err)
}
for _, p := range result {
if p.PageID > 0 {
results = append(results, &FundraisingPageRef{
charityID: charityID,
eventID: p.EventID,
id: p.PageID,
shortName: p.PageShortName,
})
}
}
return results, nil
}
示例6: sendMail
func sendMail(output []byte, subject string, fromAddress string, toAddresses []string) {
smtpServer := "smtp.blah.org"
from := mail.Address{"Code Review Request", "[email protected]"}
auth := smtp.PlainAuth(
"",
"[email protected]",
"password",
smtpServer,
)
header := make(map[string]string)
header["From"] = from.String()
header["To"] = toAddresses[0]
header["Subject"] = subject
header["MIME-Version"] = "1.0"
header["Content-Type"] = "text/plain; charset=\"utf-8\""
header["Content-Transfer-Encoding"] = "base64"
message := ""
for k, v := range header {
message += fmt.Sprintf("%s: %s\r\n", k, v)
}
message += "\r\n" + base64.StdEncoding.EncodeToString(output)
err := smtp.SendMail(smtpServer+":587", auth, from.Address, toAddresses, []byte(message))
LogError(err)
log.Printf("Email sent. %s", strings.Join(toAddresses, ","))
}
示例7: Message
// Message to render a ses.SendEmailInput
func Message(Sender *mail.Address, ToUsers []*mail.Address, Subject,
Content string) *ses.SendEmailInput {
var mailCharset = aws.String("UTF-8")
var toUsers []*string
toUsers = make([]*string, len(ToUsers))
for i, v := range ToUsers {
toUsers[i] = aws.String(v.String())
}
return &ses.SendEmailInput{
Destination: &ses.Destination{
ToAddresses: toUsers,
},
Message: &ses.Message{
Body: &ses.Body{
HTML: &ses.Content{
Charset: mailCharset,
Data: aws.String(Content),
},
},
Subject: &ses.Content{
Charset: mailCharset,
Data: aws.String(Subject),
},
},
Source: aws.String(Sender.String()),
}
}
示例8: SetRecipient
// SetRecipient sets the receiver of the email
func (email *Email) SetRecipient(address string) {
var recipient = mail.Address{
Address: address,
}
email.recipient = []string{recipient.Address}
email.header["To"] = recipient.String()
}
示例9: main
func main() {
addr := mail.Address{"Jim Green", "[email protected]"}
fmt.Println(addr.String())
// Output: =?utf-8?q?Jim_Green?= <[email protected]>
addr = mail.Address{"中文", "[email protected]"}
fmt.Println(addr.String())
// Output: =?utf-8?q?=E4=B8=AD=E6=96=87?= <[email protected]>
}
示例10: MakeHeader
func (m *FeedMailer) MakeHeader(recipient mail.Address) string {
header = make(map[string]string)
header["MIME-Version"] = "1.0"
header["From"] = m.Sender.String()
header["To"] = recipient.String()
header["Subject"] = "Go lang updates"
header["Content-type"] = "text/html"
return toString(header)
}
示例11: sendContactFormEmail
func sendContactFormEmail(smtpUser string,
smtpPass string,
smtpServer string,
to []*mail.Address,
from *mail.Address,
subject string,
body string) error {
recipients := ""
toAddresses := make([]string, 0, 10)
for _, addr := range to {
toAddresses = append(toAddresses, addr.Address)
recipients += fmt.Sprintf("%s, ", addr.String())
}
header := make(map[string]string)
header["From"] = from.String()
header["To"] = recipients
header["Subject"] = subject
header["MIME-Version"] = "1.0"
header["Content-Type"] = "text/plain; charset=\"utf-8\""
header["Content-Transfer-Encoding"] = "base64"
message := ""
for k, v := range header {
message += fmt.Sprintf("%s: %s\r\n", k, v)
}
message += "\r\n"
message += "\r\n" + base64.StdEncoding.EncodeToString([]byte(body))
auth := smtp.PlainAuth(
"",
smtpUser,
smtpPass,
smtpServer,
)
// Connect to the server, authenticate, set the sender and recipient,
// and send the email all in one step.
err := smtp.SendMail(
smtpServer+":25",
auth,
from.Address,
toAddresses,
[]byte(message),
)
if err != nil {
log.Printf("Error sending mail: %v", err)
return err
} else {
log.Printf("Sent mail to %s without error: ", recipients)
}
log.Println("Finished trying to send email")
return nil
}
示例12: NewMessage
// NewMessage builds a new message instance
func NewMessage(from, to *mail.Address, subject string,
htmlContent string) (*email.Email, error) {
msg := &email.Email{
From: from.String(),
To: []string{to.String()},
Subject: subject,
HTML: []byte(htmlContent),
}
return msg, nil
}
示例13: makeToAddresses
func makeToAddresses(to []string) string {
var toString string
for i, t := range to {
ma := mail.Address{Address: t}
toString += ma.String()
if i != len(to)-1 {
// add comma between addresses unless it's the last one
toString += ", "
}
}
return toString
}
示例14: CreateMailFromItem
// CreateMailFromItem returns a Message containing the given story.
func CreateMailFromItem(from string, to mail.Address, item *feed.Story) *gomail.Message {
content := FormatMessageBody(item)
gmsg := gomail.NewMessage()
gmsg.SetHeader("From", from)
gmsg.SetHeader("To", to.String())
gmsg.SetHeader("Subject", item.Title)
gmsg.SetBody("text/html", content)
if !item.Published.IsZero() {
gmsg.SetHeader("Date", item.Published.UTC().Format(time.RFC822))
}
return gmsg
}
示例15: InsertHandler
func InsertHandler(w http.ResponseWriter, r *http.Request) {
var newSubscriber mail.Address
newSubscriber.Name = r.FormValue("Name")
newSubscriber.Address = r.FormValue("Email-id")
if newSubscriber.Address == "" {
fmt.Fprintf(w, "Sorry the email field cannot be left empty")
} else if isPresent(newSubscriber.Address) == true {
fmt.Fprintf(w, "Sorry the email address is already taken")
} else {
AddSubscriber(newSubscriber)
fmt.Fprintf(w, "You have succesfully subscribed")
}
}