dsjojts9734 2016-06-27 02:41
浏览 113

去SMTP发送电子邮件

I am trying to send an email using Go. however I try to use my host custom mail servers wich are the followings

enter image description here

So I am not quite sure what should I use over here. I am doing the following

auth := smtp.PlainAuth("", "noreply@icon-universe.com", "password", "mail.icon-universe.com")
log.Println(smtp.SendMail("mail.icon-universe.com:25", auth, "noreply@icon-universe.com", []string{"to@gmail.com"}, []byte("This is a simple test")))

However this would give me the following error

x509: certificate is valid for server.premierehost.net, www.server.premierehost.net, not mail.icon-universe.com

So then I tried the following

auth := smtp.PlainAuth("", "noreply@icon-universe.com", "password", "server.premierehost.net")
log.Println(smtp.SendMail("server.premierehost.net:465", auth, "noreply@icon-universe.com", []string{"nakotoffana@gmail.com"}, []byte("thanks for loggin in")))

However this would just make my app go on an infinite loop...

Wich connection details should I use?

--- Update

I decided to try go-mail and seems to work but not for @gmail

d := gomail.NewDialer("server.premierehost.net", 465, "noreply@icon-universe.com", "password")
m := gomail.NewMessage()
m.SetHeader("From", "noreply@icon-universe.com")
m.SetHeader("To", "carvajal@karmagameworks.com")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
log.Println(d.DialAndSend(m))

This will work and the email will appear but sending to @gmail.com wont (the email will never arrive)

  • 写回答

1条回答 默认 最新

  • doudao7113 2017-04-15 15:42
    关注

    You appear to be using gomail correctly, but you should make sure the email account on gmail you are trying to send from has less secure apps turned on, otherwise this will never actually send.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入