转到,Appengine,SMTP,Gmail

For some reason I cannot figure out how to send emails using a gmail account, Appengine and Golang.

Here's what I've done:

I went to Google Cloud Platform > Appengine > Settings > Select Project and I added the gmail account on Email API authorized senders.

I' tried to make this work using the code from (https://golang.org/pkg/net/smtp/#pkg-examples) (func SendMail)


package main

import (

    "log"
    "net/smtp"
)

func main() {

    // Set up authentication information.
    auth := smtp.PlainAuth("", "user@gmail.com", "password", "smtp.gmail.com")

    // Connect to the server, authenticate, set the sender and recipient,
    // and send the email all in one step.
    to := []string{"recipient@example.net"}
    msg := []byte("To: recipient@example.net
" +
        "Subject: discount Gophers!
" +
        "
" +
        "This is the email body.
")
    err := smtp.SendMail(smtp.gmail.com:587", auth, "sender@example.org", to, msg)
    if err != nil {
        log.Fatal(err)
    }
}

On the front-end (JavaScript) I get an unsuccessful response after trying to run this code.

I've been running this on the appengine staging server

I tried different smtp server, ports, users and it still not work (support.google.com/a/answer/176600?hl=en)

I found a few examples on github and some other blog and I tried them but it didn't make different. github.com/golang/go/wiki/SendingMail

nathanleclaire.com/blog/2013/12/17/sending-email-from-gmail-using-golang/

On all the examples it everything looks straight forward but there's something that I'm definitely missing or misunderstanding.

There're some limitations with establishing raw tcp connections on GAE: https://cloud.google.com/appengine/docs/go/sockets/#limitations_and_restrictions

I would recommend to use GAE mail api (which is slightly diffrent from standart smtp package) to send emails: https://cloud.google.com/appengine/docs/go/mail/sending-receiving-with-mail-api