婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Go語言通過smtp發送郵件的方法

Go語言通過smtp發送郵件的方法

熱門標簽:旅游廁所如何電子地圖標注 海外照相館地圖標注入駐 外呼系統多少錢一年 經常接到推銷電話機器人的電話 智能營銷軟件 客服級電銷機器人 工商信用卡外呼系統教程 外呼系統如何接收服務密碼 滁州自建外呼系統

本文實例講述了Go語言通過smtp發送郵件的方法。分享給大家供大家參考。具體實現方法如下:

復制代碼 代碼如下:
package main
import (
 "net/smtp"
 "fmt"
 "strings"
)

/*
 * user : example@example.com login smtp server user
 * password: xxxxx login smtp server password
 * host: smtp.example.com:port   smtp.163.com:25
 * to: example@example.com;example1@163.com;example2@sina.com.cn;...
 *  subject:The subject of mail
 *  body: The content of mail
 *  mailtyoe: mail type html or text
 */


func SendMail(user, password, host, to, subject, body, mailtype string) error{
 hp := strings.Split(host, ":")
 auth := smtp.PlainAuth("", user, password, hp[0])
 var content_type string
 if mailtype == "html" {
  content_type = "Content-Type: text/"+ mailtype + "; charset=UTF-8"
 }else{
  content_type = "Content-Type: text/plain" + "; charset=UTF-8"
 }

 msg := []byte("To: " + to + "\r\nFrom: " + user + ""+ user +">\r\nSubject: " + subject + "\r\n" + content_type + "\r\n\r\n" + body)
 send_to := strings.Split(to, ";")
 err := smtp.SendMail(host, auth, user, send_to, msg)
 return err
}

func main() {
 user := "xxxx@163.com"
 password := "xxxx"
 host := "smtp.163.com:25"
 to := "xxxx@gmail.com;ssssss@gmail.com"

 subject := "Test send email by golang"

 body := `
 html>
 body>
 h3>
 "Test send email by golang"
 /h3>
 /body>
 /html>
 `
 fmt.Println("send email")
 err := SendMail(user, password, host, to, subject, body, "html")
 if err != nil {
  fmt.Println("send mail error!")
  fmt.Println(err)
 }else{
  fmt.Println("send mail success!")
 }
}

希望本文所述對大家的Go語言程序設計有所幫助。

您可能感興趣的文章:
  • golang實現通過smtp發送電子郵件的方法
  • go語言發送smtp郵件的實現示例

標簽:楚雄 湘潭 晉城 九江 深圳 運城 喀什 本溪

巨人網絡通訊聲明:本文標題《Go語言通過smtp發送郵件的方法》,本文關鍵詞  語言,通過,smtp,發送,郵件,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Go語言通過smtp發送郵件的方法》相關的同類信息!
  • 本頁收集關于Go語言通過smtp發送郵件的方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 于都县| 泸定县| 镇沅| 庆阳市| 多伦县| 玉屏| 石狮市| 武邑县| 太保市| 贵溪市| 佛学| 阿克陶县| 新竹市| 怀仁县| 高台县| 宁晋县| 隆林| 盈江县| 丹凤县| 洞头县| 苏州市| 道孚县| 松潘县| 和静县| 呼和浩特市| 宿州市| 兰州市| 项城市| 沁源县| 兴隆县| 双江| 河津市| 库尔勒市| 环江| 罗江县| 岳阳市| 昌图县| 阿克苏市| 乐业县| 乌拉特后旗| 山丹县|