校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > 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發送郵件的方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 靖西县| 阳城县| 阜平县| 拜泉县| 灵山县| 榆社县| 曲麻莱县| 新兴县| 鄯善县| 万荣县| 芦山县| 尤溪县| 乐东| 资兴市| 武山县| 集贤县| 齐齐哈尔市| 临泉县| 宽甸| 百色市| 九龙城区| 定结县| 石阡县| 田阳县| 五大连池市| 龙海市| 郁南县| 门源| 松溪县| 岫岩| 广饶县| 壤塘县| 迁安市| 巫溪县| 仁怀市| 修文县| 绍兴市| 金堂县| 游戏| 若羌县| 新和县|