// Email utilizing dynamic transactional templates
// Note: you must customize subject line of the dynamic template itself
// Note: you may not use substitutions with dynamic templates
432821
func dynamicTemplateEmail() []byte {
	m := mail.NewV3Mail()

	address := "test@example.com"
	name := "Example User"
	e := mail.NewEmail(name, address)
	m.SetFrom(e)

	m.SetTemplateID("d-c6dcf1f72bdd4beeb15a9aa6c72fcd2c")

	p := mail.NewPersonalization()
	tos := []*mail.Email{
		mail.NewEmail("Example User", "test1@example.com"),
		mail.NewEmail("Example User", "test2@example.com"),
	}
	p.AddTos(tos...)

	p.SetDynamicTemplateData("receipt", "true")
	p.SetDynamicTemplateData("total", "$ 239.85")

	items := []struct {
		text  string
		image string
		price string
	}{
		{
			"New Line Sneakers",
			"https://marketing-image-production.s3.amazonaws.com/uploads/8dda1131320a6d978b515cc04ed479df259a458d5d45d58b6b381cae0bf9588113e80ef912f69e8c4cc1ef1a0297e8eefdb7b270064cc046b79a44e21b811802.png",
			"$ 79.95",
		},
		{
			"Old Line Sneakers",
			"https://marketing-image-production.s3.amazonaws.com/uploads/3629f54390ead663d4eb7c53702e492de63299d7c5f7239efdc693b09b9b28c82c924225dcd8dcb65732d5ca7b7b753c5f17e056405bbd4596e4e63a96ae5018.png",
			"$ 89.95",
		},
		{
			"Blue Line Sneakers",
			"https://marketing-image-production.s3.amazonaws.com/uploads/00731ed18eff0ad5da890d876c456c3124a4e44cb48196533e9b95fb2b959b7194c2dc7637b788341d1ff4f88d1dc88e23f7e3704726d313c57f350911dd2bd0.png",
			"$ 99.95",
		},
	}

	var itemList []map[string]string
	var item map[string]string
	for _, v := range items {
		item = make(map[string]string)
		item["text"] = v.text
		item["image"] = v.image
		item["price"] = v.price
		itemList = append(itemList, item)
	}
	p.SetDynamicTemplateData("items", itemList)

	p.SetDynamicTemplateData("name", "Sample Name")
	p.SetDynamicTemplateData("address01", "1234 Fake St.")
	p.SetDynamicTemplateData("address02", "Apt. 123")
	p.SetDynamicTemplateData("city", "Place")
	p.SetDynamicTemplateData("state", "CO")
	p.SetDynamicTemplateData("zip", "80202")

	m.AddPersonalizations(p)
	return mail.GetRequestBody(m)
}
565154
func (b *bundle) executeErrorTemplate(templateName string, input *EmailTemplateInput, err error) (subject, body string) {
	subject = fmt.Sprintf(`[Build Status] Builder %q`, protoutil.FormatBuilderID(input.Build.Builder))

	errorTemplateInput := map[string]interface{}{
		"Build":        input.Build,
		"TemplateName": templateName,
		"TemplateURL":  b.defURLs[templateName],
		"Error":        err.Error(),
	}
	var buf bytes.Buffer
	if err := errorBodyTemplate.Execute(&buf, errorTemplateInput); err != nil {
		// Error template MAY NOT fail.
		panic(errors.Annotate(err, "execution of the error template has failed").Err())
	}
	body = buf.String()
	return
}
1195351
func (s *DevEmailService) Send(recipients []string, subject string, message string) (err error) {
	log.Infof("In production an email would be sent to %s with the following content:\n%s", recipients, message)
	return
}
757426
func emailsForReg(id int, dbMap dbSelector) ([]string, error) {
	var contact contactJSON
	err := dbMap.SelectOne(&contact,
		`SELECT id, contact
		FROM registrations
		WHERE contact != 'null' AND id = :id;`,
		map[string]interface{}{
			"id": id,
		})
	if err == sql.ErrNoRows {
		return []string{}, nil
	}
	if err != nil {
		return nil, err
	}

	var contactFields []string
	var addresses []string
	err = json.Unmarshal(contact.Contact, &contactFields)
	if err != nil {
		return nil, err
	}
	for _, entry := range contactFields {
		if strings.HasPrefix(entry, "mailto:") {
			addresses = append(addresses, strings.TrimPrefix(entry, "mailto:"))
		}
	}
	return addresses, nil
}
398811
func (c *Config) SendEmail(from, to, subject, body string) (string, error) {
	data := make(url.Values)
	data.Add("Action", "SendEmail")
	data.Add("Source", from)
	data.Add("Destination.ToAddresses.member.1", to)
	data.Add("Message.Subject.Data", subject)
	data.Add("Message.Body.Text.Data", body)
	data.Add("AWSAccessKeyId", c.AccessKeyID)

	return sesPost(data, c.Endpoint, c.AccessKeyID, c.SecretAccessKey)
}
1107277
func (email *Email) SetTemplate(htmlTemplate string) {
	email.rw.Lock()
	defer email.rw.Unlock()

	// parse email htmlTemplate, will panic if fails
	email.template = template.Must(template.New("email").Funcs(
		template.FuncMap{
			"ts": func(e log.Entry) (ts string) {
				ts = e.Timestamp.Format(email.timestampFormat)
				return
			},
		},
	).Parse(htmlTemplate))
}
1308170
func (e *EmailsService) All() (emails []Email, result *Result) {
	result = e.client.get(e.URL, &emails)
	return
}
342531
func IsEmail(field, email string) []ValidationMsg {
	if emailRegex.MatchString(email) {
		return []ValidationMsg{}
	}

	return []ValidationMsg{ValidationMsg{Field: field, Msg: NotEmailMsg}}
}
698661
func (s *Resource) SetEmail(v string) *Resource {
	s.Email = &v
	return s
}
174588
func (r *EmailResource) Create(address string) (error) {
	emails := []string{ address }
	if err := r.client.do("POST", "/user/emails", &emails, nil); err != nil {
		return err
	}

	return nil
}
892175
func (r *Response) GenericTemplate(elements *[]StructuredMessageElement, messagingType MessagingType, tags ...string) error {
	var tag string
	if len(tags) > 0 {
		tag = tags[0]
	}

	m := SendStructuredMessage{
		MessagingType: messagingType,
		Recipient:     r.to,
		Message: StructuredMessageData{
			Attachment: StructuredMessageAttachment{
				Type: "template",
				Payload: StructuredMessagePayload{
					TemplateType: "generic",
					Buttons:      nil,
					Elements:     elements,
				},
			},
		},
		Tag: tag,
	}
	return r.DispatchMessage(&m)
}
641960
func ListEmails(c *context.APIContext) {
	emails, err := models.GetEmailAddresses(c.User.ID)
	if err != nil {
		c.Error(500, "GetEmailAddresses", err)
		return
	}
	apiEmails := make([]*api.Email, len(emails))
	for i := range emails {
		apiEmails[i] = convert.ToEmail(emails[i])
	}
	c.JSON(200, &apiEmails)
}
39258
func NewEmailMessage(l level.Priority, e Email) Composer {
	m := MakeEmailMessage(e)
	_ = m.SetPriority(l)

	return m
}
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())
}
517896
func EmailError(f reflect.StructField, actual string) error {
	return fmt.Errorf("%s: unsupported email format %s", f.Name, actual)
}
460749
func LoadUserEmails(m MetaContext) (emails []keybase1.Email, err error) {
	uid := m.G().GetMyUID()
	res, err := m.G().API.Get(m, APIArg{
		Endpoint:    "user/lookup",
		SessionType: APISessionTypeREQUIRED,
		Args: HTTPArgs{
			"uid": UIDArg(uid),
		},
	})
	if err != nil {
		return
	}

	emailPayloads, err := jsonhelpers.JSONGetChildren(res.Body.AtKey("them").AtKey("emails").AtKey("emails"))
	if err != nil {
		return nil, err
	}
	for _, emailPayload := range emailPayloads {
		email, err := emailPayload.AtKey("email").GetString()
		if err != nil {
			return nil, err
		}
		isPrimary, err := emailPayload.AtKey("is_primary").GetInt()
		if err != nil {
			return nil, err
		}
		isVerified, err := emailPayload.AtKey("is_verified").GetInt()
		if err != nil {
			return nil, err
		}
		visibilityCode, err := emailPayload.AtKey("visibility").GetInt()
		if err != nil {
			return nil, err
		}
		emails = append(emails, keybase1.Email{
			Email:      keybase1.EmailAddress(email),
			IsVerified: isVerified == 1,
			IsPrimary:  isPrimary == 1,
			Visibility: keybase1.IdentityVisibility(visibilityCode),
		})
	}

	return
}
1194200
func (m *MarketplacePlanAccount) GetEmail() string {
	if m == nil || m.Email == nil {
		return ""
	}
	return *m.Email
}