go-gomail / gomail

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

send email with no auth #17

Closed ipartner closed 9 years ago

ipartner commented 9 years ago

Hi. I need to use a relay server to send email. there is no user and no sender account. but the library looks like its you need to auth every time.

alexcesaro commented 9 years ago

Can you detail a bit more? How do you send emails exactly?

ipartner commented 9 years ago

We need to send mail w/o auth using your library. But looking at the api it only offers send via auth( may I be wrong)

So There is a way just to send a mail via a relay server without any auth?

Enviado desde mi iPhone

El 14-01-2015, a las 19:03, Alexandre Cesaro notifications@github.com escribió:

Can you detail a bit more? How do you send emails exactly?

— Reply to this email directly or view it on GitHub.

alexcesaro commented 9 years ago

Then you should create a mailer using NewCustomMailer and use nil as an smtp.Auth.

alexcesaro commented 9 years ago

Hello, it would be cool if you tried Gomail v2 (still unstable) and tell me if it works:

package main

import (
    "gopkg.in/gomail.v2-unstable"
)

func main() {
    m := gomail.NewMessage()
    m.SetHeader("From", "from@example.com")
    m.SetHeader("To", "to@example.com")
    m.SetHeader("Subject", "Test")
    m.SetBody("text/html", "Test")

    d := &gomail.Dialer{Host: "smtp.example.org", Port: 587}
    if err := d.DialAndSend(m); err != nil {
        panic(err)
    }
}
jasonwee commented 2 years ago

Hello, it would be cool if you tried Gomail v2 (still unstable) and tell me if it works:

package main

import (
    "gopkg.in/gomail.v2-unstable"
)

func main() {
    m := gomail.NewMessage()
    m.SetHeader("From", "from@example.com")
    m.SetHeader("To", "to@example.com")
    m.SetHeader("Subject", "Test")
    m.SetBody("text/html", "Test")

    d := &gomail.Dialer{Host: "smtp.example.org", Port: 587}
    if err := d.DialAndSend(m); err != nil {
        panic(err)
    }
}

you might want to add the following InsecureSkipVerify to true when sending to localhost because normally localhost dont have a ssl cert.

d := &gomail.Dialer{Host: "smtp.example.org", Port: 25}
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}

if you don't add that, you will get this

panic: x509: certificate is not valid for any names, but wanted to match localhost