2016-12-08 9 views
2

何らかの理由で、私は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それすべてまっすぐに見えるが、私は間違いなく間違っているか誤解している何かがある。

+0

を参考: 私のGmailアカウントを使用してあなたのコードを電子メールで送信しました。 – doharlem

+0

コードをローカルまたはGoogle Appengineで使用しましたか? App Engine上で動作が少し異なる点はほとんどありません。 –

+0

がローカルにあります。 hm ...私の唯一の推測はポートです。 telnet smtp.gmail.com 587はあなたのインスタンスから動作しますか? – doharlem

答えて

0

はGAE上で生のTCP接続を確立すると、いくつかの制限がありませ: https://cloud.google.com/appengine/docs/go/sockets/#limitations_and_restrictions

私は電子メール送信する(スタンダールSMTPパッケージから少し切り抜いです)GAEメールAPIを使用することをお勧めします: https://cloud.google.com/appengine/docs/go/mail/sending-receiving-with-mail-api

+0

私はそれを行います。私はあなたの助けに感謝します! –

関連する問題