Backup Code

I dont have chinese inputmethod now ( what the fuck about Linux KDE envirnment !) , so just leave some message for this backup code about golang email . I remember that I had written this function a long time ago , but I can not find it out just now . Some code was searched on Internet .

This is a example for QQ email . But you can use other email ,eg 163,yahoo... But you must config the server smtp address .

Here it is :

// EmailMain
package main import (
"fmt"
"net/smtp"
"strings"
) const(
HOST = "smtp.qq.com"
SERVER_ADDR = "smtp.qq.com:25"
USER = "624432528@qq.com"
PASSWORD = "xxxx"
) type Email struct {
to string "to"
subject string "subject"
msg string "msg"
} func NewEmail(to,subject,msg string) *Email{
return &Email{to:to,subject:subject,msg:msg}
} func SendEmail(email *Email) error{
auth := smtp.PlainAuth("",USER,PASSWORD,HOST)
sendTo := strings.Split(email.to,";")
done := make(chan error,1024) go func(){
defer close(done)
for _,v := range sendTo {
//warning ; the last \r\n need twice , not only one .
str := strings.Replace("From:"+USER+"~To :"+v+"~Subject:"+email.subject+"~Content-Type: text/plain;charset=UTF-8~","~","\r\n",-1)+"\r\n"+email.msg
fmt.Println("Content:",str)
err := smtp.SendMail(SERVER_ADDR,auth,USER,[]string{v},[]byte(str))
if err != nil{
fmt.Println("Send Error:",err)
}
done <- err
}
}() for i:=0;i<len(sendTo);i++{
<- done
} return nil
} func main() {
email := NewEmail("798207330@qq.com","How Are you","Hello World , I am wang")
err := SendEmail(email)
fmt.Println("result:",err)
}

Golang Email的更多相关文章

  1. Golang优秀开源项目汇总, 10大流行Go语言开源项目, golang 开源项目全集(golang/go/wiki/Projects), GitHub上优秀的Go开源项目

    Golang优秀开源项目汇总(持续更新...)我把这个汇总放在github上了, 后面更新也会在github上更新. https://github.com/hackstoic/golang-open- ...

  2. 一个发邮件的demo 用golang

    一个比较成熟的第三方包用来发邮件,可以带图片 和附件,项目地址 : github.com/go-gomail/gomail 一个发邮件的demo 用golang 文件目录树: -d:\test\goe ...

  3. go语言项目汇总

    Horst Rutter edited this page 7 days ago · 529 revisions Indexes and search engines These sites prov ...

  4. go语言正则表达式

    我们前两节课爬取珍爱网的时候,用到了很多正则表达式去匹配城市列表.城市.用户信息,其实除了正则表达式去匹配,还可以利用goquery和xpath第三方库匹配有用信息.而我利用了更优雅的正则表达式匹配. ...

  5. Go之发送钉钉和邮箱

    smtp发送邮件 群发两个邮箱,一个163,一个QQ package main import ( "fmt" "net/smtp" "strings& ...

  6. golang学习之beego框架配合easyui实现增删改查及图片上传

    golang学习之beego框架配合easyui实现增删改查及图片上传 demo目录: upload文件夹主要放置上传的头像文件,main是主文件,所有效果如下: 主页面: 具体代码: <!DO ...

  7. 在C++中使用golang的协程

    开源项目cpp_features提供了一个仿golang协程的stackful协程库. 可以在c++中使用golang的协程,大概语法是这样的: #include <iostream> v ...

  8. 依据 smtp协议的简单golang 的发邮件实现

    依据 smtp协议的简单golang 的发邮件实现 协议格式如下 From:sender_user@demo.net To:to_user@demo.net Subject:这是主题 Mime-Ver ...

  9. Go语言(golang)开源项目大全

    转http://www.open-open.com/lib/view/open1396063913278.html内容目录Astronomy构建工具缓存云计算命令行选项解析器命令行工具压缩配置文件解析 ...

随机推荐

  1. keepalived配虚拟ip(vip)的作用

    keepalived是以VRRP协议为实现基础的,VRRP全称Virtual Router Redundancy Protocol,即虚拟路由冗余协议. 虚拟路由冗余协议,可以认为是实现路由器高可用的 ...

  2. Gazebo: Could not find parameter robot_description on parameter server

    robot_state_publisher looks for the parameter "robot_description" by default. The robot_st ...

  3. m序列c语言实现

    演示,不是算法 void m4() { int a[4]={1,0,0,1}; int m[15]; int temp; for(int i=0;i<15;i++){ m[i] = a[0]; ...

  4. 449. Serialize and Deserialize BST

    https://leetcode.com/problems/serialize-and-deserialize-bst/#/description Serialization is the proce ...

  5. Django之admin管理数据库,cookie验证及分页设置

    一.admin管理数据库 1)models.py创建class类表 class Book(models.Model): name=models.CharField(max_length=) price ...

  6. 2019.01.23 ural1519 Formula 1(轮廓线dp)

    传送门 轮廓线dpdpdp模板题. 题意简述:给一个放有障碍的网格图,问有多少种方法能使所有非障碍格子都在同一条哈密顿回路上面. 考虑用括号序列的写法来状压这个轮廓线. 用000表示没有插头,111表 ...

  7. 安装配置ftp服务器

    1.安装ftp服务 检查是否安装vsftpd rpm -qa|grep vsftpd 安装 vsftpd yum -y install vsftpd 2.配置 编辑 文件 /etc/vsftpd/vs ...

  8. Transforming Real-Time Task Graphs to Improve Schedulability

    Basic idea:  insert artificial delays to the release times of certain vertices of a task graph to ge ...

  9. Mybatis-Plus 实战完整学习笔记(十)------条件构造器核心用法大全(下)

    31.升序orderByAsc 31.升序orderByAsc List<Employee> employeeList = employeeMapper.selectList(new Qu ...

  10. BZOJ 2440 [中山市选2011]完全平方数 (二分 + 莫比乌斯函数)

    2440: [中山市选2011]完全平方数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 4805  Solved: 2325[Submit][Sta ...