本文整理匯總了Golang中appengine/mail.Send函數的典型用法代碼示例。如果您正苦於以下問題:Golang Send函數的具體用法?Golang Send怎麽用?Golang Send使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Send函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SendEmail
/**
* send email
* @param {[type]} r *http.Request [description]
* @param {[type]} model string [description]
* @param {[type]} data map[string]string data to fo to template
* @param {[type]} sub string subject
* @param {[type]} to string receiver email
* @param {[type]} from string sender email
*/
func SendEmail(r *http.Request, model string, data map[string]string, sub string, to string, from string) error {
templateFile, err := ioutil.ReadFile("email_templates/" + model)
if err != nil {
return err
}
templateString := string(templateFile)
tmpl, err := template.New("email").Parse(templateString)
if err != nil {
return err
}
var doc bytes.Buffer
err = tmpl.Execute(&doc, data)
if err != nil {
return err
}
body := doc.String()
c := appengine.NewContext(r)
msg := &mail.Message{
Sender: "Call For Paper <" + from + ">",
To: []string{to},
Subject: sub,
HTMLBody: body,
}
if err := mail.Send(c, msg); err != nil {
return err
}
return nil
}
示例2: SendMail
func SendMail(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
vars := mux.Vars(r)
address := vars["email"]
m := &mail.Message{
Sender: "kyokomi-dev<[email protected]>",
// ReplyTo: "",
To: []string{address},
// Cc: "",
// Bcc: []string{},
Subject: "Test Mail",
Body: "サンプルメールを送信。",
HTMLBody: "",
// Attachments: []Attachment{},
// Headers: mail.Header{},
}
if err := mail.Send(c, m); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/", http.StatusFound)
}
示例3: TriggerSubscriptionsIfNeeded
func TriggerSubscriptionsIfNeeded(check alert.Check, subscriptions []Subscription, context appengine.Context) {
for _, subscription := range subscriptions {
if check.Changed && check.CurrentState > check.PreviousState {
log.Infof(context, "Firing Subscrption %v", subscription)
subject := fmt.Sprintf("Alert %s changed state from %s to %s", check.Alert,
alert.GetStateString(check.PreviousState), alert.GetStateString(check.CurrentState))
message := fmt.Sprintf("Alert %s changed state from %s to %s with value %f\n Value measured at %s.\n", check.Alert,
alert.GetStateString(check.PreviousState), alert.GetStateString(check.CurrentState),
check.Value, time.Now().UTC().String())
msg := &mail.Message{
Sender: "Klaxon <[email protected]>",
To: []string{subscription.Target},
Subject: subject,
Body: message,
}
if err := mail.Send(context, msg); err != nil {
log.Errorf(context, "Couldn't send email: %v", err)
}
}
}
}
示例4: handleSendPage
func handleSendPage(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
//addr := r.FormValue("email")
//url := createConfirmationURL(r)
params, err := parseTemplateParams()
if err != nil {
c.Errorf("template execution: %s", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
c.Infof("Sender:", fmt.Sprintf(templateMailFrom, params.MailSenderName, params.MailSenderEmail))
addrs := []string{"[email protected]"}
msg := &mail.Message{
Sender: fmt.Sprintf(templateMailFrom, params.MailSenderName, params.MailSenderEmail),
To: addrs,
Subject: "Confirm your registration",
Body: fmt.Sprintf(confirmMessage, "Test text"),
}
if err := mail.Send(c, msg); err != nil {
c.Errorf("template execution: %s", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
示例5: sendReminder
func sendReminder(c appengine.Context, date time.Time) {
addr := "[email protected]"
tag := fmt.Sprintf("diaryentry%dtag", rand.Int63())
item := &memcache.Item{
Key: tag,
Value: []byte(date.Format(time.RFC850)),
}
// Add the item to the memcache, if the key does not already exist
if err := memcache.Add(c, item); err == memcache.ErrNotStored {
c.Infof("item with key %q already exists", item.Key)
} else if err != nil {
c.Errorf("error adding item: %v", err)
}
msg := &mail.Message{
Sender: "Automatic Diary <[email protected]>",
To: []string{addr},
Subject: "Entry reminder",
Body: fmt.Sprintf(reminderMessage, tag),
}
if err := mail.Send(c, msg); err != nil {
c.Errorf("Couldn't send email: %v", err)
return
}
c.Infof("Reminder mail sent for %v", date)
c.Infof("body: %v", msg.Body)
}
示例6: doInitiateResetPassword
func doInitiateResetPassword(email string, c *Context) error {
// Check that it's a known user email.
userId, user := GetUserFromEmailOrDie(email, c)
// Create the ResetPassword record.
v := &ResetPassword{
UserId: userId,
Timestamp: time.Now(),
}
key := NewEphemeralKey(c.Aec(), "ResetPassword")
key, err := datastore.Put(c.Aec(), key, v)
if err != nil {
return err
}
// Send the email.
resetUrl := prependHost(fmt.Sprintf("/account/change-password?key=%s", key.Encode()), c)
data := map[string]interface{}{
"fullName": user.FullName,
"email": user.Email,
"resetUrl": resetUrl,
}
body, err := ExecuteTextTemplate("email-reset-password.txt", data)
if err != nil {
return err
}
msg := &mail.Message{
Sender: "Tadue <[email protected]>",
To: []string{user.Email},
Subject: "Reset your Tadue password",
Body: body,
}
return mail.Send(c.Aec(), msg)
}
示例7: sendAlert
// sendAlert sends an alert email about the potential car hijacking.
func sendAlert(c appengine.Context, accKeyID int64, alertMsg, bodyTempl string) {
// load account
acc := new(ds.Account)
key := datastore.NewKey(c, ds.ENameAccount, "", accKeyID, nil)
if err := datastore.Get(c, key, acc); err != nil {
c.Errorf("Failed to load account: %v", err)
return
}
const adminEmail = "Andras Belicza <[email protected]>"
msg := &mail.Message{
Sender: adminEmail,
To: []string{acc.Email},
ReplyTo: adminEmail,
Subject: "[IczaGPS] ALERT: " + alertMsg,
Body: fmt.Sprintf(bodyTempl, acc.Email),
}
if len(acc.ContactEmail) > 0 {
msg.Cc = []string{acc.ContactEmail}
}
if err := mail.Send(c, msg); err == nil {
c.Infof("Sent successful alert email: %s", alertMsg)
} else {
c.Errorf("Couldn't send alert email: %s, %v", alertMsg, err)
}
}
示例8: sendMail
// Sends an email to the author of part with a link to continue.
func sendMail(c appengine.Context, story Story) {
if story.Complete {
return
}
var subject, text string
part := story.LastPart()
url := fmt.Sprintf(serverUrl, story.Id, story.NextId)
if part != nil {
subject = "Please write the next part of this story."
text = fmt.Sprintf("%s, %s wrote:\n> %s\n\nPlease visit %s to write the next part.",
capital(fuzzyTime(part.Written)), getFullEmail(c, part.Author), part.Visible, url)
} else {
subject = "Please write the first part of this story."
text = fmt.Sprintf("%s, %s initiated a new story.\n\nPlease visit %s to write the beginning.",
capital(fuzzyTime(story.Created)), getFullEmail(c, story.Creator), url)
}
msg := &mail.Message{
Sender: sender,
To: []string{story.NextAuthor},
Subject: subject,
Body: text,
}
if err := mail.Send(c, msg); err != nil {
c.Errorf("Couldn't send email: %v", err)
panic(err)
}
}
示例9: unregisterUser
func unregisterUser(addr string, c appengine.Context) {
q := datastore.NewQuery(USER_MODEL).
Filter("Email =", addr).
KeysOnly()
keys, err := q.GetAll(c, nil)
if err != nil {
c.Errorf("Cound not query the model for %s: %v", addr, err)
return
}
if len(keys) == 0 {
c.Infof("No such user to unregister: %s", addr)
return
}
for i := range keys {
datastore.Delete(c, keys[i])
}
c.Infof("Removed user %s", addr)
msg := &gaeMail.Message{
Sender: "[email protected]",
To: []string{addr},
Subject: "Email unregistered",
Body: "user " + addr + " has been unregistered",
}
gaeMail.Send(c, msg)
}
示例10: submit
func submit(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
name := r.FormValue("name")
email := r.FormValue("email")
message := "<html><body><h3>Contact:</h3><p>Phone: " + r.FormValue("phone") + "<br/>Message: " + r.FormValue("message") + "</p><h3>Order:</h3><p>" + r.FormValue("order") + "</p></body></html>"
msg := &mail.Message{
Sender: name + " <[email protected]>",
To: []string{"[email protected]"},
ReplyTo: email,
Subject: "DCHCM Received New Order",
//Body: message,
HTMLBody: message,
Headers: netMail.Header{
//"Content-Type": []string{"text/html; charset=UTF-8"},
"On-Behalf-Of": []string{email},
},
}
if code := r.FormValue("code"); code != "12345" {
c.Errorf("Wrong code: %v", code)
http.Error(w, "{\"status\":\"Code invalid! Try again\", \"code\":401}", http.StatusUnauthorized)
} else if err := mail.Send(c, msg); err != nil {
c.Errorf("Couldn't send email: %v", err)
http.Error(w, "{\"status\":\"Mail NOT send! Error\", \"code\":500}", http.StatusInternalServerError)
} else {
c.Infof("Mail send:\n %v", message)
fmt.Fprint(w, "{\"status\":\"Mail send\", \"code\":200}")
}
}
示例11: contact
func contact(w http.ResponseWriter, r *http.Request) {
var submitted string
if r.Method == "POST" {
c := appengine.NewContext(r)
name := r.FormValue("name")
email := r.FormValue("email")
info := r.FormValue("info")
if name == "" || email == "" || info == "" {
submitted = "Submission failed. Please enter all the information on the form. Thanks!"
} else {
msg := &mail.Message{
Sender: "[email protected]",
To: []string{"[email protected]"},
Subject: fmt.Sprintf("Website Contact - %s", name),
Body: fmt.Sprintf("Name: %s\nEmail: %s\nInformation: %s", name, email, info),
HTMLBody: fmt.Sprintf("<html><body><p>Name: %s</p><p>Email: %s</p><p>Information: %s</p></body></html>", name, email, info),
}
if err := mail.Send(c, msg); err != nil {
c.Errorf("Could not send email: %v", err)
submitted = "Your information could not be sent. Could you try again later? Apologies!"
} else {
submitted = "Your information has been sent. I'll get back to you as soon as possible!"
}
}
c.Infof("Contact submitted: name=%s, email=%s, info=%s", name, email, info)
}
out := mustache.RenderFileInLayout("mustache/contact.html.mustache", "mustache/layout.html.mustache", map[string]string{"submitted": submitted})
fmt.Fprint(w, out)
}
示例12: emailSend
func emailSend(w http.ResponseWriter, r *http.Request, m map[string]string) {
c := appengine.NewContext(r)
//addr := r.FormValue("email")
if _, ok := m["subject"]; !ok {
m["subject"] = "empty subject line"
}
email_thread_id := []string{"3223"}
msg := &ae_mail.Message{
//Sender: "Peter Buchmann <[email protected]",
// Sender: "[email protected]",
Sender: "[email protected]",
//To: []string{addr},
To: []string{"[email protected]"},
Subject: m["subject"],
Body: "some_body some_body2",
Headers: go_mail.Header{"References": email_thread_id},
}
err := ae_mail.Send(c, msg)
util_err.Err_http(w, r, err, false, "could not send the email")
}
示例13: MailNotifications
// MailNotifications finds all the users interested in the topic of the conference
// and sends them an email notifying the conference.
//
// This operation can be slow and shouldn't be performed in the critical path of the
// application.
func (conf *Conference) MailNotifications(ctx appengine.Context, sender, subject, body string) error {
ks, err := datastore.NewQuery(UserKind).
Filter("Topics =", conf.Topic).
KeysOnly().
GetAll(ctx, nil)
if err != nil {
return fmt.Errorf("get interested users: %v", err)
}
to := make([]string, len(ks))
for i, k := range ks {
to[i] = k.StringID()
}
msg := &mail.Message{
Sender: sender,
To: to,
Subject: subject,
Body: body,
}
if err := mail.Send(ctx, msg); err != nil {
return fmt.Errorf("send mail: %v", err)
}
return nil
}
示例14: contactRequestHandler
func contactRequestHandler(w http.ResponseWriter, r *http.Request) {
name := r.FormValue("name")
email := r.FormValue("email")
subject := r.FormValue("subject")
message := r.FormValue("message")
if len(email) == 0 {
fmt.Fprint(w, "invalid request")
return
}
context := appengine.NewContext(r)
mailMessage := &mail.Message{
Sender: name + " <[email protected]>",
ReplyTo: email,
To: []string{"[email protected]"},
Subject: subject,
Body: message,
}
if error := mail.Send(context, mailMessage); error != nil {
context.Errorf("the email could not be sent: %v", error)
}
http.ServeFile(w, r, "static/html/contact/contact_sent.html")
}
示例15: SendMail
// Sends post notification mail
func SendMail(c appengine.Context, entry Entry) error {
config, err := ParseConfig("./config/mailConfig.json")
if err != nil {
return err
}
// Prepares email message
msg := new(mail.Message)
msg.Sender = config.Sender
msg.To = make([]string, 1)
msg.To[0] = config.To
msg.Subject = "New post made from Legacy-BBS-Go"
var body bytes.Buffer
var mailTemplate = template.Must(template.ParseFiles("template/notificationMailTemplate.txt"))
if err := mailTemplate.Execute(&body, entry); err != nil {
return err
}
msg.Body = body.String()
if err := mail.Send(c, msg); err != nil {
return err
}
c.Infof("Notification mail sent to \"" + config.To + "\"")
return nil
}