域名生成企业邮箱golang企业邮箱发邮件 golang gmail发邮件
一 在自己的域名控制臺 找到企業(yè)郵箱的模塊 我的是騰訊的有免費開通。開通后就可以前往控制臺
二 前往控制臺 添加MX記錄
從ID點進去
就到了郵箱詳情 可以到達郵箱管理
三 掃碼 登陸 在這個客戶端收發(fā)里能找到很多有用的幫助
四:
進入管理郵箱
開啟你想使用賬號的SMTP服務(wù)
然后重新登陸到你開啟SMTP服務(wù)的郵箱頁面,找到設(shè)置–郵箱綁定–客戶端專用密碼–生成新密碼
復(fù)制下來你的密碼 沾到你的代碼里
// QQ 郵箱://host := "smtp.qq.com"//port := 25//userName := "93XXXXXX68@qq.com"//password := "vXXXXXqxknhbdac"// Gmail 郵箱://host := "smtp.gmail.com" //port := 465//userName := "xxxxx@gmail.com"//password := "pogxxxxxxxxxxxl"// 騰訊企業(yè)郵箱服務(wù)器 郵箱:host := "smtp.exmail.qq.com"port := 465userName := "notify@你的域名.域名后綴"password := "你剛才復(fù)制的密碼"整體代碼如下:
package logicimport ("crypto/tls""fmt""gopkg.in/gomail.v2""paas/dao/mysql""paas/models" )func SendNotice(notice *models.Notice) error {var message stringtemplate01_noticeTask := `<p> Hello 山陰路的夏天 %s,</p><p style="text-indent:2em">test test test test test test test test test test test test.</p> `template02_noticeDeadline := `<p> Hello 天空之城 %s,</p><p style="text-indent:2em">test test test test test test test test test test test test.</p> `template03_noticeReward := `<p> Hello 熱河路 %s,</p><p style="text-indent:2em">test test test test test test test test test test test test.</p> <p style="text-indent:2em">test test test test test test test test test test test test.</p><p style="text-indent:2em">test test test test test test test test test test test test.</P><p style="text-indent:2em">Best Wishes!</p>`switch notice.Attribute {case 1:message = template01_noticeTaskcase 2:message = template02_noticeDeadlinecase 3:message = template03_noticeReward}emails, err := mysql.FindKolEmail(notice.Address)if err != nil {return err}fmt.Println(emails)//或者將模版存數(shù)據(jù)庫字典里 從字典里取//noticeDic := mysql.SYS_DIC["notice"]//for _, vmap := range noticeDic {// for k, v := range vmap {// if k == notice.Attribute {// template = v// }// }//}// QQ 郵箱:// SMTP 服務(wù)器地址:smtp.qq.com(SSL協(xié)議端口:465/994 | 非SSL協(xié)議端口:25) (SMTP服務(wù)器(端口465或587)???)// 163 郵箱:// SMTP 服務(wù)器地址:smtp.163.com(端口:25)// QQ 郵箱://host := "smtp.qq.com"//port := 25//userName := "900000008@qq.com"//password := "vxxxxxxxxknhbdac"// Gmail 郵箱://host := "smtp.gmail.com"//port := 465//userName := "xxxxxxx@gmail.com"//password := "xxxxxxpgpbywjnl"// 騰訊企業(yè)郵箱服務(wù)器(metaverseman.asia) 郵箱:host := "smtp.exmail.qq.com"port := 465userName := "notify@metaverseman.asia"password := "xxxxxxxxUJotjxdi"m := gomail.NewMessage()m.SetHeader("From", userName) // 發(fā)件人// m.SetHeader("From", "alias"+"<"+userName+">") // 增加發(fā)件人別名m.SetHeader("To", "987xxxxx@qq.com") // 收件人,可以多個收件人,但必須使用相同的 SMTP 連接m.SetHeader("Cc", emails[0]) // 抄送,可以多個m.SetHeader("Cc", "xxxxxxxxxx@qq.com") // 抄送,可以多個m.SetHeader("Bcc", "xxxxxxxxx@gmail.com") // 暗送,可以多個m.SetHeader("Subject", "Hello!") // 郵件主題// text/html 的意思是將文件的 content-type 設(shè)置為 text/html 的形式,瀏覽器在獲取到這種文件時會自動調(diào)用html的解析器對文件進行相應(yīng)的處理。// 可以通過 text/html 處理文本格式進行特殊處理,如換行、縮進、加粗等等m.SetBody("text/html", fmt.Sprintf(message, "testUser"))// text/plain的意思是將文件設(shè)置為純文本的形式,瀏覽器在獲取到這種文件時并不會對其進行處理// m.SetBody("text/plain", "純文本")// m.Attach("test.sh") // 附件文件,可以是文件,照片,視頻等等// m.Attach("lolcatVideo.mp4") // 視頻// m.Attach("lolcat.jpg") // 照片d := gomail.NewDialer(host,port,userName,password,)// 關(guān)閉SSL協(xié)議認證d.TLSConfig = &tls.Config{InsecureSkipVerify: true}if err := d.DialAndSend(m); err != nil {panic(err)return err}return nil }然后就可以測試接口了 可以發(fā)現(xiàn) 國內(nèi)的郵件還是比較絲滑的 。但是我給我自己gmail抄送的 都失敗了 。
這里代碼只是初版 實際業(yè)務(wù)并發(fā)量大的情況也可以考慮將用mq任務(wù)隊列加進來。
~~~~~~~~~~~~~~~~~~~~~~~~~
以上是由域名到開通企業(yè)郵箱再到開通指定郵箱的SMTP功能和生成密碼 接入【代碼客戶端】的全過程。這是我用騰訊云買的域名測試的。實際公司是海外域名和服務(wù)器,還沒來得及搞,但是流程肯定是類似的。國內(nèi)的企業(yè)郵箱的玩法應(yīng)該也類似。下面再說下個人郵箱的測試。
~~~~~~~~~~~~~~~~~~~~~~~~~
QQ比較簡單 自己找一下
Gmail測試的時候,是要先在谷歌賬號 安全性 開啟【兩步驗證】后才會出現(xiàn)【應(yīng)用專用密碼】的欄目。
選好點生成 就會生成密碼了 然后沾到你代碼里使用。選擇應(yīng)用的時候不會選就選其他 自定義名稱就行。
總結(jié)
以上是生活随笔為你收集整理的域名生成企业邮箱golang企业邮箱发邮件 golang gmail发邮件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机之父
- 下一篇: 如何将多个文件的简体中文名快速翻译成繁体