golang发送邮件

u012210379 · · 9966 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

经测试成功 转自http://blog.csdn.net/zistxym/article/details/20235023

package main
 
import (
        "log"
        "net/smtp"
        "flag"
        "fmt"
        "strings"
)
 
var (
    subject = flag.String( "s","","subject of the mail" )
    body= flag.String( "b","","body of themail" )
    reciMail = flag.String( "m","","recipient mail address" )
)
 
func main() {
        // Set up authentication information.
        flag.Parse()
        sub := fmt.Sprintf("subject: %s\r\n\r\n",*subject)
        content :=  *body
        mailList := strings.Split( *reciMail,",")
 
        auth := smtp.PlainAuth(
                "",
                "smtpuser@example.com",
                "password",
                "smtp.example.com",
                //"smtp.gmail.com",
        )
        // Connect to the server, authenticate, set the sender and recipient,
        // and send the email all in one step.
        err := smtp.SendMail(
                "smtp.example.com:25",
                auth,
                "senduser@example.com",
                mailList,
                []byte(sub+content),
        )
        if err != nil {
                log.Fatal(err)
        }
}


//该代码片段来自于: http://www.sharejs.com/codes/go/5641



附:各大免费邮箱邮件群发账户SMTP服务器配置及SMTP发送量限制情况

http://www.freehao123.com/mail-smtp/

其中:

QQ邮箱POP3服务器(端口995):qq.com,SMTP服务器(端口465或587):smtp.qq.com,账户名:您的QQ邮箱账户名(如果您是VIP帐号或Foxmail帐号,账户名需要填写完整的邮件地址),密码:您的QQ邮箱密码,电子邮件地址:您的QQ邮箱的完整邮件地址。

-------------------------------------------------------------------------------------------------------------------------------------------------------

网易免费邮箱SMTP 服务器:smtp.126.com,smtp.163.com, smtp.yeah.net, SSL:否,服务器端口:25 ,发送延时 20秒,163VIP邮箱:每天限制最多能发送800封邮件。163 、 126 、 yeah 的邮箱:一封邮件最多发送给  40  个收件人 , 每天发送限额为 50 封。

-------------------------------------------------------------------------------------------------------------------------------------------------------

2009年7月30日新浪正式推出CN免费邮箱,新浪免费邮箱发信(smtp)服务器的地址为:smtp.sina.com,收信(pop3)服务器的地址为:pop.sina.com,设置完成后,注意一定要选择smtp服务器要求身份验证选项。



有疑问加站长微信联系(非本文作者)

本文来自:CSDN博客

感谢作者:u012210379

查看原文:golang发送邮件

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

9966 次点击  ∙  1 赞  
加入收藏 微博
1 回复  |  直到 2018-12-11 14:35:29
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传