Home > database >  Lambda Function(Go) can't send email with SES SMTP
Lambda Function(Go) can't send email with SES SMTP

Time:08-31

Hello I've followed the instructions here to try and get my lambda function able to send email via SES SMTP https://docs.aws.amazon.com/ses/latest/dg/send-email-set-up-vpc-endpoints.html

In my Lambda Function I use the net/smtp package and when I try to send the email it gives me this error

Error sending email alert dial tcp: lookup email-smtp.us-east-1.amazonaws.com on ..*.1:53: no such host

Here is the code for sending the email that is giving me issues. Note when I rung this Go code locally it works fine.


    user := os.Getenv("SMTP_USER")
    password := os.Getenv("SMTP_PASSWORD")

    to := []string{
        "[email protected]",
    }

    addr := "email-smtp.us-east-1.amazonaws.com:587"
    host := "email-smtp.us-east-1.amazonaws.com"

    msg := []byte("From: [email protected]\r\n"  
        "To: [email protected]\r\n"  
        "Subject: Test mail\r\n\r\n"  
        "Email Body \r\n")

    auth := smtp.PlainAuth("", user, password, host)

    err = smtp.SendMail(addr, auth, from, to, msg)```

CodePudding user response:

I was able to finally get the SMTP working. Everything in that document in the OP was correct except the security group part. In order to get it to work, I had to set the inbound and outbound rules of my security group (not entirely sure if outbound is necessary) to use the entire IP address range of the subnet in my VPC for use1-az1 for source/destination respectively.

  • Related