當前位置: 首頁>>代碼示例>>Golang>>正文


Golang mail.Address類代碼示例

本文整理匯總了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
}
開發者ID:no2key,項目名稱:postman,代碼行數:35,代碼來源:mail.go

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

}
開發者ID:homemade,項目名稱:justin,代碼行數:32,代碼來源:justin.go

示例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)
	}
}
開發者ID:robert-zaremba,項目名稱:sendgrid-go,代碼行數:8,代碼來源:mail.go

示例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))
}
開發者ID:joakim666,項目名稱:ismonitor,代碼行數:33,代碼來源:mail.go

示例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
}
開發者ID:homemade,項目名稱:justin,代碼行數:61,代碼來源:justin.go

示例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, ","))
}
開發者ID:andyb,項目名稱:RandomReview,代碼行數:28,代碼來源:review.go

示例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()),
	}
}
開發者ID:toomore,項目名稱:simpleaws,代碼行數:31,代碼來源:ses.go

示例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()
}
開發者ID:coddo,項目名稱:gost,代碼行數:9,代碼來源:email.go

示例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]>
}
開發者ID:JamesJiangCHN,項目名稱:gopkg,代碼行數:8,代碼來源:ExampleAddress.go

示例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)
}
開發者ID:shreyaganguly,項目名稱:reddit-mailer,代碼行數:9,代碼來源:mailer.go

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

}
開發者ID:diatoming,項目名稱:contactformhandler,代碼行數:55,代碼來源:main.go

示例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
}
開發者ID:kevgathuku,項目名稱:postman,代碼行數:12,代碼來源:mail.go

示例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
}
開發者ID:joakim666,項目名稱:ismonitor,代碼行數:12,代碼來源:mail.go

示例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
}
開發者ID:hobeone,項目名稱:rss2go,代碼行數:13,代碼來源:mail.go

示例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")
	}
}
開發者ID:shreyaganguly,項目名稱:reddit-mailer,代碼行數:13,代碼來源:web.go


注:本文中的net/mail.Address類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。