go-gomail / gomail

The best way to send emails in Go.
MIT License
4.3k stars 570 forks source link

Unencrypted connection #113

Open vladoohr opened 6 years ago

vladoohr commented 6 years ago

Hello,

I am getting the followinfg error: unencrypted connection. I am using MailHog as SMTP server.

Here is the code snipped:

func Send(mailInfo Info, cfg config.Config, template string) error { d := gomail.NewDialer(cfg.Mail["host"], port, cfg.Mail["user"], cfg.Mail["password"])

d.TLSConfig = &tls.Config{InsecureSkipVerify: true}

err = d.DialAndSend(message)

return err

}

How I can use unencrypted connection with this library?

Thanks in advance.

webluoye commented 6 years ago

use go 1.9 or support ssl mail server

pedromorgan commented 6 years ago

See #108

wickerplane commented 5 years ago

TL;DR: try setting your username (third argument ingomail.NewDialer) to an empty string

This seems to be a built in yet undocumented workaround that allows you to bypass these two if blocks from Dial() in gomail/smtp.go:

if d.Auth == nil && d.Username != "" {
        if ok, auths := c.Extension("AUTH"); ok {
            if strings.Contains(auths, "CRAM-MD5") {
                d.Auth = smtp.CRAMMD5Auth(d.Username, d.Password)
            } else if strings.Contains(auths, "LOGIN") &&
                !strings.Contains(auths, "PLAIN") {
                d.Auth = &loginAuth{
                    username: d.Username,
                    password: d.Password,
                    host:     d.Host,
                }
            } else {
                d.Auth = smtp.PlainAuth("", d.Username, d.Password, d.Host)
            }
        }
    }

    if d.Auth != nil {
        if err = c.Auth(d.Auth); err != nil {
            c.Close()
            return nil, err
        }
    }
weiye301 commented 2 years ago

Did you finally solve it and how to do it?

gyqsophila commented 1 year ago

@wickerplane but get another error : client is not auth to send anoymous mail FROM, have any idea ?

pedromorgan commented 1 year ago

see #182 ;-((