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. 移动端300ms延迟由来及解决方案

    1.300ms延迟由来 300 毫秒延迟的主要原因是解决双击缩放(double tap to zoom).双击缩放,顾名思义,即用手指在屏幕上快速点击两次,iOS 自带的 Safari 浏览器会将网页 ...

  2. velocity 框架

    Java模板引擎 Velocity是一个基于java的模板引擎(template engine).它允许任何人仅仅使用简单的模板语言(template language)来引用由java代码定义的对象 ...

  3. 【Web】Sublime Text 3 连接sftp/ftp(远程服务器)

    在 Win 下常用 Xftp 软件来和远程服务传递文件,但是要是在项目开发的时候频繁的将远程文件拖到本地编辑然后再传回远程服务器,那真是麻烦无比,但是Sublime中SFTP插件,它让这世界美好了许多 ...

  4. svn checkout单个文件

    http://www.letuknowit.com/archives/svn-checkout-single-file/ 有时候需要在svn版本仓库中某个比较上层的目录中(比如根目录)checkout ...

  5. 使用 kbmmw 的ORM开发纯REST数据库访问服务

    运行环境: WIN 10  X64 delphi 10.2.2 kbmmw 5.05.11 Firefox 58.0.2 今天使用最新的kbmmw 版本做一个基于ORM的纯数据库访问的REST 服务器 ...

  6. 2018.11.17 bzoj4259: 残缺的字符串(fft)

    传送门 fftfftfft套路题. 我们把aaa ~ zzz映射成111 ~ 262626,然后把∗*∗映射成000. 考虑对于两个长度都为nnn的字符串A,BA,BA,B. 我们定义一个差异函数di ...

  7. jquery 特效

    http://demo.howtoexe.com/instagram-gravity-gallery/index.html

  8. (13)How to stay calm when you know you'll be stressed

    https://www.ted.com/talks/daniel_levitin_how_to_stay_calm_when_you_know_you_ll_be_stressed/transcrip ...

  9. (5)How to let go of being a "good" person — and become a better person

    https://www.ted.com/talks/dolly_chugh_how_to_let_go_of_being_a_good_person_and_become_a_better_perso ...

  10. Router pipeline

    from 2013-HPCA-Breaking the On-Chip Latency Barrier Using SMART book_Principles and Practices of Int ...