Could you try this SendMail function (using gomail.SetSendMail(sendMail))
and tell me if it works when the certificate is invalid?
func sendMail(addr string, a smtp.Auth, from string, to []string, msg
[]byte) error {
c, err := smtp.Dial(addr)
if err != nil {
return err
}
defer c.Close()
if ok, _ := c.Extension("STARTTLS"); ok {
host, _, _ := net.SplitHostPort(addr)
config := &tls.Config{ServerName: host, InsecureSkipVerify: true}
if err = c.StartTLS(config); err != nil {
return err
}
}
if a != nil {
if ok, _ := c.Extension("AUTH"); ok {
if err = c.Auth(a); err != nil {
return err
}
}
}
if err = c.Mail(from); err != nil {
return err
}
for _, addr := range to {
if err = c.Rcpt(addr); err != nil {
return err
}
}
w, err := c.Data()
if err != nil {
return err
}
_, err = w.Write(msg)
if err != nil {
return err
}
err = w.Close()
if err != nil {
return err
}
return c.Quit()
}
On Mon, Oct 20, 2014 at 3:56 PM, Alexandre Cesaro wrote:Ok, this is often requested so I will work on an alternative SendMail
function.
On Sat, Oct 18, 2014 at 12:14 PM, Klaus Post wrote:Very funny - I just ran into the exact same issue yesterday. I tried to
copy the send function from smtp to my own package, but I gave up since it
relied on to much package stuff.
The issue is that TLS in the golang smtp package always attempts smtp, if
the server announces it. If it fails (we have an expired certificate in our
case), the client fails, and doesn't attempt a non-TLS connection.
See
http://golang.org/src/pkg/net/smtp/smtp.go?s=1593:1652#L282 for the
offending code path.
So yes - if you could make TLS optional that would be great.
/Klaus
PS. Thanks for the nice package, it has been very easy to use!
On Friday, October 17, 2014 8:28:18 PM UTC+2, Jonas Riedel wrote:Nice thing !
Could you provide a send function where the tls config is exposed so
that one is able to set the InsecureSkipVerify flag for StartTLS ?
Thanks,
Jonas
Am Donnerstag, 26. Juni 2014 18:28:54 UTC+2 schrieb Alexandre Cesaro:
Hello, I wrote a new package: gomail. It provides a simple interface to
easily write and send emails. It supports attachments, multipart emails and
encoding of non-ASCII characters.
Documentation:
http://godoc.org/github.com/alexcesaro/mail/gomailSource code:
https://github.com/alexcesaro/mail/Here is an example:
package main
import (
"log"
"github.com/alexcesaro/mail/gomail"
)
func main() {
msg := gomail.NewMessage()
msg.SetAddressHeader("From", "al...@example.com", "Alex")
msg.SetHeader("To", "b...@example.com")
msg.AddHeader("To", "co...@example.com")
msg.SetHeader("Subject", "Hello!")
msg.SetBody("text/plain", "Hello Bob and Cora!")
msg.AddAlternative("text/html", "Hello <b>Bob</b> and
<i>Cora</i>!")
if err := msg.Attach("/home/Alex/lolcat.jpg"); err != nil {
log.Println(err)
return
}
m := gomail.NewMailer("smtp.example.com", "user", "123456", 25)
if err := m.Send(msg); err != nil { // This will send the email
to Bob and Cora
log.Println(err)
}
}
Hope you will enjoy it! Feedback is welcome!
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.