Sen Email with out Authentication

HI
Could you please tell me how to write the Go program to send the email without smtp Authentication,
thanks

Sudesh

2 Likes

You do not want to authenticate against the application or you do not want to authenticate the application against the mailserver?

If its the former, its just as with authentication, but you can skip the specific parts that ask for PW and stuff.

If its the latter, I hope you won’t find a service that allows that…

2 Likes

I would suggest to use this package: https://github.com/go-mail/mail.

2 Likes

smtp.SendMail accepts an optional smtp.Auth parameter. You can set it to nil:

package main
  
import (
    "fmt"
    "net/smtp"
)       

func main() {
    msg := []byte("To: to@example.com\r\n" +
        "Subject: Hi there!\r\n" +
        "Content-Type: text/plain; charset=UTF-8\r\n" +
        "\r\n" +                      
        "Hi!\r\n")                            
    to := make([]string, 1)                       
    to[0] = "to@example.com"                          
    err := smtp.SendMail("smtp.example.com:25",
      nil /* this is the optional Auth */,
      "from@example.com", to, msg)
    fmt.Println(err)                                          
} 
3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.