237
手机大全
SMTP之GO调用示例__SMTP接口说明_邮件推送-阿里云
package main
import (
"fmt"
"net/smtp"
"strings"
)
func SendToMail(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 + "rnFrom: " + user + "rnSubject: " + subject + "rn" + content_type + "rnrn" + body)
send_to := strings.Split(to, ";")
err := smtp.SendMail(host, auth, user, send_to, msg)
return err
}
func main() {
user := "控制台创建的发信地址"
password := "控制台设置的SMTP密码"
host := "smtpdm.aliyun.com:25"
to := "目标地址"
subject := "test Golang to sendmail"
body := `
<html>
<body>
<h3>
"Test send to email"
</h3>
</body>
</html>
`
fmt.Println("send email")
err := SendToMail(user, password, host, to, subject, body, "html")
if err != nil {
fmt.Println("Send mail error!")
fmt.Println(err)
} else {
fmt.Println("Send mail success!")
}
}
最后更新:2016-11-24 11:23:48
上一篇:
SMTP之nodejs调用示例__SMTP接口说明_邮件推送-阿里云
下一篇:
JavaSDK手册__SDK使用手册_邮件推送-阿里云
聚合函数__函数_SQL语法参考_云数据库 OceanBase-阿里云
目标模式__场景制定_使用手册_性能测试-阿里云
如何申请备案服务号?__产品验证_备案流程_备案-阿里云
ALIYUN::ECS::SecurityGroupEgress__资源列表_资源编排-阿里云
域名绑定__脚本编写_使用手册_性能测试-阿里云
漏洞等级说明__漏洞说明_先知计划-阿里云
如何完成企业实名认证__实名认证_帐号实名认证_会员账号&实名认证-阿里云
2016-09-29__Release-Notes_日志服务-阿里云
软件配置__用户指南_E-MapReduce-阿里云
ModifyLoadBalancerInternetSpec__LoadBalancer相关API_API 参考_负载均衡-阿里云
相关内容
常见错误说明__附录_大数据计算服务-阿里云
发送短信接口__API使用手册_短信服务-阿里云
接口文档__Android_安全组件教程_移动安全-阿里云
运营商错误码(联通)__常见问题_短信服务-阿里云
设置短信模板__使用手册_短信服务-阿里云
OSS 权限问题及排查__常见错误及排除_最佳实践_对象存储 OSS-阿里云
消息通知__操作指南_批量计算-阿里云
设备端快速接入(MQTT)__快速开始_阿里云物联网套件-阿里云
查询API调用流量数据__API管理相关接口_API_API 网关-阿里云
使用STS访问__JavaScript-SDK_SDK 参考_对象存储 OSS-阿里云