当前位置: 首页>>代码示例>>Golang>>正文


Golang Address.String方法代码示例

本文整理汇总了Golang中net/mail.Address.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Address.String方法的具体用法?Golang Address.String怎么用?Golang Address.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net/mail.Address的用法示例。


在下文中一共展示了Address.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: sendResetPasswordEmail

func sendResetPasswordEmail(member Member) {
	templateFile := "./templates/resetpasswordemail.html"
	templateData, err := ioutil.ReadFile(templateFile)

	resetPasswordUri := fmt.Sprintf("%s?t=%s", getResetPasswordUri(), member.Password_reset_token)
	body := strings.Replace(string(templateData), "<<memberEmail>>", member.Email, -1)
	body = strings.Replace(body, "<<resetPasswordUri>>", resetPasswordUri, -1)

	// Set up authentication information.
	// https://gist.github.com/andelf/5004821
	auth := smtp.PlainAuth("", getSmtpUser(), getSmtpPass(), getSmtpHost())

	from := mail.Address{"Support", getSmtpUser()}
	to := mail.Address{member.Email, member.Email}
	title := "Reset password"
	header := make(map[string]string)
	header["From"] = from.String()
	header["To"] = to.String()
	header["Subject"] = title
	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([]byte(body))

	err = smtp.SendMail(getSmtpHost()+getSmtpPort(), auth, from.Address, []string{to.Address}, []byte(message))
	if err != nil {
		fmt.Println(err)
	}
}
开发者ID:rafikmajidov,项目名称:crossfitlogger,代码行数:34,代码来源:mail.go

示例2: main

func main() {
	host := "192.168.0.243:25"

	from := mail.Address{"发件人", "[email protected]"}
	to := mail.Address{"收件人", "[email protected]"}
	header := make(map[string]string)
	header["From"] = from.String()
	header["To"] = to.String()
	b64 := base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
	header["Subject"] = fmt.Sprintf("=?UTF-8?B?%s?=", b64.EncodeToString([]byte("标题测试")))
	header["MIME-Version"] = "1.0"
	header["Content-Type"] = "text/html; charset=UTF-8"
	header["Content-Transfer-Encoding"] = "base64"

	body := "邮件正文"

	message := ""

	for k, v := range header {
		message += fmt.Sprintf("%s: %s\r\n", k, v)
	}
	message += "\r\n" + b64.EncodeToString([]byte(body))
	//auth := smtp.PlainAuth("", "", "", host)
	err := smtp.SendMail(host, nil, "[email protected]", []string{to.Address}, []byte(message))
	fmt.Println(err)
}
开发者ID:tzm529,项目名称:studygo,代码行数:26,代码来源:sendmail.go

示例3: 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
}
开发者ID:homemade,项目名称:justin,代码行数:61,代码来源:justin.go

示例4: 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

}
开发者ID:homemade,项目名称:justin,代码行数:32,代码来源:justin.go

示例5: 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()),
	}
}
开发者ID:toomore,项目名称:simpleaws,代码行数:31,代码来源:ses.go

示例6: 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))
}
开发者ID:joakim666,项目名称:ismonitor,代码行数:33,代码来源:mail.go

示例7: 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
}
开发者ID:no2key,项目名称:postman,代码行数:35,代码来源:mail.go

示例8: 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, ","))
}
开发者ID:andyb,项目名称:RandomReview,代码行数:28,代码来源:review.go

示例9: SendMail

func SendMail(to, subject, body string) *model.AppError {

	if len(Cfg.EmailSettings.SMTPServer) == 0 || Cfg.EmailSettings.ByPassEmail {
		return nil
	}

	fromMail := mail.Address{Cfg.EmailSettings.FeedbackName, Cfg.EmailSettings.FeedbackEmail}
	toMail := mail.Address{"", to}

	headers := make(map[string]string)
	headers["From"] = fromMail.String()
	headers["To"] = toMail.String()
	headers["Subject"] = html.UnescapeString(subject)
	headers["MIME-version"] = "1.0"
	headers["Content-Type"] = "text/html"

	message := ""
	for k, v := range headers {
		message += fmt.Sprintf("%s: %s\r\n", k, v)
	}
	message += "\r\n<html><body>" + body + "</body></html>"

	conn, err1 := connectToSMTPServer()
	if err1 != nil {
		return err1
	}
	defer conn.Close()

	c, err2 := newSMTPClient(conn)
	if err2 != nil {
		return err2
	}
	defer c.Quit()
	defer c.Close()

	if err := c.Mail(fromMail.Address); err != nil {
		return model.NewAppError("SendMail", "Failed to add from email address", err.Error())
	}

	if err := c.Rcpt(toMail.Address); err != nil {
		return model.NewAppError("SendMail", "Failed to add to email address", err.Error())
	}

	w, err := c.Data()
	if err != nil {
		return model.NewAppError("SendMail", "Failed to add email messsage data", err.Error())
	}

	_, err = w.Write([]byte(message))
	if err != nil {
		return model.NewAppError("SendMail", "Failed to write email message", err.Error())
	}

	err = w.Close()
	if err != nil {
		return model.NewAppError("SendMail", "Failed to close connection to SMTP server", err.Error())
	}

	return nil
}
开发者ID:netroby,项目名称:platform,代码行数:60,代码来源:mail.go

示例10: 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)
	}
}
开发者ID:robert-zaremba,项目名称:sendgrid-go,代码行数:8,代码来源:mail.go

示例11: 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()
}
开发者ID:coddo,项目名称:gost,代码行数:9,代码来源:email.go

示例12: 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]>
}
开发者ID:JamesJiangCHN,项目名称:gopkg,代码行数:8,代码来源:ExampleAddress.go

示例13: SendRecoveryEmail

// SendRecoveryEmail dispatches predefined recovery email to recipient defined in parameters.
// Makes use of https://gist.github.com/andelf/5004821
func SendRecoveryEmail(id, name, address, recovery string) error {

	var email Email
	email.Sender = Settings.Mailer.Login
	email.Host = Settings.URL.String()
	email.Recipient.ID = id
	email.Recipient.Name = name
	email.Recipient.Address = address
	email.Recipient.RecoveryKey = recovery

	from := mail.Address{Settings.Name, email.Sender}
	to := mail.Address{email.Recipient.Name, email.Recipient.Address}
	title := "Password reset"

	t, err := template.New("mail").Parse(RecoveryTemplate)
	if err != nil {
		return err
	}

	var buf bytes.Buffer
	err = t.Execute(&buf, email)
	if err != nil {
		return err
	}

	header := make(map[string]string)
	header["From"] = from.String()
	header["To"] = to.String()
	header["Subject"] = title
	header["MIME-Version"] = "1.0"
	header["Content-Type"] = "text/plain; charset=\"utf-8\""
	header["Content-Transfer-Encoding"] = "base64"

	var message string
	for k, v := range header {
		message += fmt.Sprintf("%s: %s\r\n", k, v)
	}
	message += "\r\n" + base64.StdEncoding.EncodeToString(buf.Bytes())

	auth := smtp.PlainAuth(
		"",
		Settings.Mailer.Login,
		Settings.Mailer.Password,
		Settings.Mailer.Hostname,
	)

	err = smtp.SendMail(
		fmt.Sprintf("%s:%d", Settings.Mailer.Hostname, Settings.Mailer.Port),
		auth,
		from.Address,
		[]string{to.Address},
		[]byte(message),
	)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:freeformz,项目名称:vertigo,代码行数:60,代码来源:email.go

示例14: 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)
}
开发者ID:shreyaganguly,项目名称:reddit-mailer,代码行数:9,代码来源:mailer.go

示例15: 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

}
开发者ID:diatoming,项目名称:contactformhandler,代码行数:55,代码来源:main.go


注:本文中的net/mail.Address.String方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。