何らかの理由で、私はGmailアカウント、AppengineとGolangを使って電子メールを送信する方法を理解できません。Go、Appengine、SMTP、Gmail
は、ここで私がやったものだ:
は、私はGoogleのクラウドプラットフォーム>のAppEngine]> [設定]> [プロジェクトに行って、私は、電子メールのAPI認可送信者のGmailアカウントを追加しました。フロントエンド(JavaScriptの)オン
I」(https://golang.org/pkg/net/smtp/#pkg-examples)からのコードを使用してこの作品を作ってみました(SendMailをFUNC)
package main
import (
"log"
"net/smtp"
)
func main() {
// Set up authentication information.
auth := smtp.PlainAuth("", "[email protected]", "password", "smtp.gmail.com")
// Connect to the server, authenticate, set the sender and recipient,
// and send the email all in one step.
to := []string{"[email protected]"}
msg := []byte("To: [email protected]\r\n" +
"Subject: discount Gophers!\r\n" +
"\r\n" +
"This is the email body.\r\n")
err := smtp.SendMail(smtp.gmail.com:587", auth, "[email protected]", to, msg)
if err != nil {
log.Fatal(err)
}
}
私はこれを実行しようとした後に失敗した応答を取得コード。
私は、私は別のSMTPサーバ、ポート、ユーザーを試してみましたが、それはまだ動作しませ
AppEngineのステージングサーバー(support.google.com/a/answer/176600?hl=en)上でこれを実行してきました
githubと他のいくつかのブログでいくつかの例を見つけましたが、試してみましたが違いはありませんでした。すべての例で
nathanleclaire.com/blog/2013/12/17/sending-email-from-gmail-using-golang/ github.com/golang/go/wiki/SendingMailそれすべてまっすぐに見えるが、私は間違いなく間違っているか誤解している何かがある。
を参考: 私のGmailアカウントを使用してあなたのコードを電子メールで送信しました。 – doharlem
コードをローカルまたはGoogle Appengineで使用しましたか? App Engine上で動作が少し異なる点はほとんどありません。 –
がローカルにあります。 hm ...私の唯一の推測はポートです。 telnet smtp.gmail.com 587はあなたのインスタンスから動作しますか? – doharlem