10

I'm working on sent emails when a user will do signup. I'm using new SendGrid account for free but while I'm running my function then it will show me the below error can anyone tell me how I' will resolve it. Below is my Golang function

func SendOtpMail(OTP string) (err error) {
    from := mail.NewEmail("Test", "test@example.com")
    subject := "Comfirmation Mail"
    to := mail.NewEmail("puneet", "puneet123@gmail.com")
    // plainTextContent := ""
    htmlContent := "Your confirmation OTP is = " + OTP
    message := mail.NewSingleEmail(from, subject, to, " ", htmlContent) // ("" = plainTextContent)
    client := sendgrid.NewSendClient("Api_key")
    response, err := client.Send(message)
    fmt.Println(response)
    fmt.Println(err)
    return err
}

In response, it will return me the below-console output:

&{403 {"errors":[{"message":"The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements","field":"from","help":null}]} map[Access-Control-Allow-Headers:[Authorization, Content-Type, On-behalf-of, x-sg-elas-acl] Access-Control-Allow-Methods:[POST] Access-Control-Allow-Origin:[https://sendgrid.api-docs.io] Access-Control-Max-Age:[600] Connection:[keep-alive] Content-Length:[281] Content-Type:[application/json] Date:[Sat, 25 Apr 2020 12:56:25 GMT] Server:[nginx] X-No-Cors-Reason:[https://sendgrid.com/docs/Classroom/Basics/API/cors.html]]}

I also implemented this same in 2019 then it is working but now I want to change it then this is showing me this error. Please help me out with this.

Puneet
  • 119
  • 1
  • 2
  • 8
  • Did you even look at the link which was provided in the error message for more information, i.e. https://sendgrid.com/docs/for-developers/sending-email/sender-identity/? Because nothing in your question suggests that you've followed the instructions there. – Steffen Ullrich Apr 25 '20 at 14:19

3 Answers3

10

Since, this is a new settings the sendgrid has created to protect your sending reputation and to uphold legitimate sending behavior, they require customers to verify their Sender Identities. Because of these old sendgrid accounts won't be affected, the accounts created after April 6, 2020 will be able to do sender Verification.

Check this docs for info - https://sendgrid.com/docs/ui/sending-email/sender-verification

Lokeshkumar S
  • 256
  • 2
  • 6
6

As per the documentation provided by sendgrid. You should authenticated sender before sending any email out,

There is two way to do it

  1. Domain Authentication
  2. Single sender authentication

Please follow below link for single sender authentication

https://sendgrid.com/docs/ui/sending-email/sender-verification

Shivam
  • 2,443
  • 17
  • 31
4
  • Verify your email

  • Restart your server

  • if still, error exists then put DEFAULT_FROM_EMAIL = yourverifiedgmail@gmail.com EMAIL_FROM=yourverifiedgmail@gmail.com

  • Restart your server the error should be gone

enter image description here