// Minimum required to send an email
773175
func helloEmail() []byte {
	address := "test@example.com"
	name := "Example User"
	from := mail.NewEmail(name, address)
	subject := "Hello World from the SendGrid Go Library"
	address = "test@example.com"
	name = "Example User"
	to := mail.NewEmail(name, address)
	content := mail.NewContent("text/plain", "some text here")
	m := mail.NewV3MailInit(from, subject, to, content)
	address = "test2@example.com"
	name = "Example User"
	email := mail.NewEmail(name, address)
	m.Personalizations[0].AddTos(email)
	return mail.GetRequestBody(m)
}
717376
func (s Service) SendEmailWithHeaders(from string, to []string, subject string, body string, headers map[string][]string) error {
	m := mail.NewMessage()
	m.SetHeaders(headers)
	m.SetHeader("From", from)
	m.SetHeader("To", to...)
	m.SetHeader("Subject", subject)
	m.SetBody("text/plain", body)

	d := mail.NewPlainDialer(
		s.SMTPHost,
		s.SMTPPort,
		s.SMTPUsername,
		s.SMTPPassword,
	)
	d.LocalName = s.SMTPIdentity
	if s.SMTPSkipVerify {
		d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
	}
	return d.DialAndSend(m)
}
896901
func VerifyActiveEmailCode(code, email string) *EmailAddress {
	minutes := setting.Service.ActiveCodeLives

	if user := parseUserFromCode(code); user != nil {
		// time limit code
		prefix := code[:tool.TIME_LIMIT_CODE_LENGTH]
		data := com.ToStr(user.ID) + email + user.LowerName + user.Passwd + user.Rands

		if tool.VerifyTimeLimitCode(data, minutes, prefix) {
			emailAddress := &EmailAddress{Email: email}
			if has, _ := x.Get(emailAddress); has {
				return emailAddress
			}
		}
	}
	return nil
}
1151463
func (m *MailerImpl) SendMail(to []string, subject, msg string) error {
	m.stats.Inc("SendMail.Attempts", 1)

	for {
		err := m.sendOne(to, subject, msg)
		if err == nil {
			// If the error is nil, we sent the mail without issue. nice!
			break
		} else if err == io.EOF {
			// If the error is an EOF, we should try to reconnect on a backoff
			// schedule, sleeping between attempts.
			m.stats.Inc("SendMail.Errors.EOF", 1)
			m.reconnect()
			// After reconnecting, loop around and try `sendOne` again.
			m.stats.Inc("SendMail.Reconnects", 1)
			continue
		} else if protoErr, ok := err.(*textproto.Error); ok && protoErr.Code == 421 {
			/*
			 *  If the error is an instance of `textproto.Error` with a SMTP error code,
			 *  and that error code is 421 then treat this as a reconnect-able event.
			 *
			 *  The SMTP RFC defines this error code as:
			 *   421 <domain> Service not available, closing transmission channel
			 *   (This may be a reply to any command if the service knows it
			 *   must shut down)
			 *
			 * In practice we see this code being used by our production SMTP server
			 * when the connection has gone idle for too long. For more information
			 * see issue #2249[0].
			 *
			 * [0] - https://github.com/letsencrypt/boulder/issues/2249
			 */
			m.stats.Inc("SendMail.Errors.SMTP.421", 1)
			m.reconnect()
			m.stats.Inc("SendMail.Reconnects", 1)
		} else if protoErr, ok := err.(*textproto.Error); ok && recoverableErrorCodes[protoErr.Code] {
			m.stats.Inc(fmt.Sprintf("SendMail.Errors.SMTP.%d", protoErr.Code), 1)
			return RecoverableSMTPError{fmt.Sprintf("%d: %s", protoErr.Code, protoErr.Msg)}
		} else {
			// If it wasn't an EOF error or a recoverable SMTP error it is unexpected and we
			// return from SendMail() with the error
			m.stats.Inc("SendMail.Errors", 1)
			return err
		}
	}

	m.stats.Inc("SendMail.Successes", 1)
	return nil
}
1176285
func ValidateEmail(r *http.Request, name string) bool {
	return ValidateString(r, name, validEmail)
}
722239
func (s *SourceImportAuthor) GetEmail() string {
	if s == nil || s.Email == nil {
		return ""
	}
	return *s.Email
}
135366
func (s *WMailServer) DeliverMail(peer *whisper.Peer, request *whisper.Envelope) {
	if peer == nil {
		log.Error("Whisper peer is nil")
		return
	}

	ok, lower, upper, bloom := s.validateRequest(peer.ID(), request)
	if ok {
		s.processRequest(peer, lower, upper, bloom)
	}
}
231860
func (mail *mailer) sendMail(subject, message string) error {
	addr := strings.Split(mail.Addr, ":")
	if len(addr) != 2 {
		return errors.New("invalid Mail Address")
	}
	host := addr[0]
	msg := []byte("To:" + strings.Join(mail.To, ";") +
		"\r\nFrom: " + mail.From +
		"\r\nSubject: " + subject +
		"\r\nContent-Type: text/plain\r\n\r\n" +
		message)
	auth := smtp.PlainAuth(
		"",
		mail.Username,
		mail.Password,
		host,
	)
	err := smtp.SendMail(
		mail.Addr,
		auth,
		mail.From,
		mail.To,
		msg,
	)
	if err != nil {
		return err
	}
	return nil
}
1290810
func (proto *Protocol) ParseMAIL(mail string) (string, error) {
	var match []string
	if proto.RejectBrokenMAILSyntax {
		match = parseMailRFCRegexp.FindStringSubmatch(mail)
	} else {
		match = parseMailBrokenRegexp.FindStringSubmatch(mail)
	}

	if len(match) != 2 {
		return "", errors.New("Invalid syntax in MAIL command")
	}
	return match[1], nil
}
937786
func (c *HTTPClientMock) SendMailV31(req *http.Request) (*http.Response, error) {
	return c.SendMailV31Func(req)
}
1001638
func (g *Generator) EMail() string {
	if g.FlipCoin(50) {
		first, _, last := g.MaleName()
		return BuildEMail(first, last, g.Domain())
	}
	first, _, last := g.FemaleName()
	return BuildEMail(first, last, g.Domain())
}
414675
func (r Account_Reports_Request) SendReportEmail(request *datatypes.Account_Reports_Request) (resp bool, err error) {
	params := []interface{}{
		request,
	}
	err = r.Session.DoRequest("SoftLayer_Account_Reports_Request", "sendReportEmail", params, &r.Options, &resp)
	return
}
1209245
func (emailServer *EmailServer) SendEmail(data *SMTPData) error {
	var doc bytes.Buffer
	t := template.New("emailTemplate")
	t, err := t.Parse(SMTPTemplate)
	if err != nil {
		log.Fatal("error trying to parse mail template", err)
		return err
	}
	err = t.Execute(&doc, data)
	if err != nil {
		log.Fatal("error tring to map data to the smtp email template", err)
		return err
	}
	err = emailServer.sendMailFunc(emailServer.host+":"+strconv.Itoa(emailServer.port),
		emailServer.auth,
		data.From,
		[]string{data.To},
		doc.Bytes())
	return err
}
865502
func (o *SMTPOptions) sendMail(m message.Composer) error {
	o.mutex.Lock()
	defer o.mutex.Unlock()

	if err := o.client.Create(o); err != nil {
		return err
	}
	defer o.client.Close()

	var subject, body string
	toAddrs := o.toAddrs
	fromAddr := o.fromAddr
	isPlainText := o.PlainTextContents
	var headers map[string][]string

	if emailMsg, ok := m.Raw().(*message.Email); ok {
		var err error
		if len(emailMsg.From) != 0 {
			fromAddr, err = mail.ParseAddress(emailMsg.From)
			if err != nil {
				return fmt.Errorf("invalid from address: %+v", err)
			}
		}

		toAddrs = make([]*mail.Address, len(emailMsg.Recipients))

		for i := range emailMsg.Recipients {
			toAddrs[i], err = mail.ParseAddress(emailMsg.Recipients[i])
			if err != nil {
				return fmt.Errorf("invalid recipient: %+v", err)
			}
		}

		subject = emailMsg.Subject
		body = emailMsg.Body
		isPlainText = emailMsg.PlainTextContents
		headers = emailMsg.Headers
	}
	if fromAddr == nil {
		return fmt.Errorf("no from address specified, cannot send mail")
	}
	if len(toAddrs) == 0 {
		return fmt.Errorf("no recipients specified, cannot send mail")
	}

	if err := o.client.Mail(fromAddr.Address); err != nil {
		return fmt.Errorf("Error establishing mail sender (%s): %+v", fromAddr, err)
	}

	var err error
	var errs []string
	var recipients []string

	// Set the recipients
	for _, target := range toAddrs {
		if err = o.client.Rcpt(target.Address); err != nil {
			errs = append(errs,
				fmt.Sprintf("Error establishing mail recipient (%s): %+v", target.String(), err))
			continue
		}
		recipients = append(recipients, target.String())
	}
	if len(errs) > 0 {
		return errors.New(strings.Join(errs, "; "))
	}

	// Send the email body.
	wc, err := o.client.Data()
	if err != nil {
		return err
	}
	defer wc.Close()

	if len(subject) == 0 && len(body) == 0 {
		subject, body = o.GetContents(o, m)
	}

	contents := []string{
		fmt.Sprintf("From: %s", fromAddr.String()),
		fmt.Sprintf("To: %s", strings.Join(recipients, ", ")),
		fmt.Sprintf("Subject: %s", subject),
		"MIME-Version: 1.0",
	}

	skipContentType := false
	for k, v := range headers {
		if k == "To" || k == "From" || k == "Subject" || k == "Content-Transfer-Encoding" {
			continue
		}
		if k == "Content-Type" {
			skipContentType = true
		}
		for i := range v {
			contents = append(contents, fmt.Sprintf("%s: %s", k, v[i]))
		}
	}

	if !skipContentType {
		if isPlainText {
			contents = append(contents, "Content-Type: text/plain; charset=\"utf-8\"")
		} else {
			contents = append(contents, "Content-Type: text/html; charset=\"utf-8\"")
		}
	}

	contents = append(contents,
		"Content-Transfer-Encoding: base64",
		base64.StdEncoding.EncodeToString([]byte(body)))

	// write the body
	_, err = bytes.NewBufferString(strings.Join(contents, "\r\n")).WriteTo(wc)
	return err
}
1245477
func (link Link) Send(m amqp.Message) (Delivery, error) {
	bytes, err := m.Encode(nil)
	if err != nil {
		return Delivery{}, err
	}
	d, err := link.SendMessageBytes(bytes)
	return d, err
}
436763
func (u *User) GetEmail() string {
	r, ok := u.Get("email")
	if ok {
		return r.(string)
	}

	return ""
}
1300778
func EmailValid(value string, basekey string, mm messages.MessageMap) error {
	if !IsEmail(value) {
		mm.Add(basekey, InvalidEmail)
		return nil
	}
	return nil
}