golang发送邮件

来源:互联网 发布:网络教育在线 编辑:程序博客网 时间:2024/06/16 03:37

经测试成功 转自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服务器要求身份验证选项。


0 0