我是AppEngine和golang的新手,并尝试使用以下代码发送电子邮件,但我没有收到任何邮件。云你请帮助解决它。
现在我直接从app引擎运行此代码,如何从本地开发服务器测试它: 的 Edited1: 当我从本地开发运行时
dev_appserver.py --smtp_host=smtp.gmail.com --smtp_port=25
--smtp_user=venkatanagarajas@gmail.com --smtp_password=****** E:\GoWork\src\email\appenginemail
我收到以下错误:
From: venkatanagarajas@gmail.com
To: Srinadh <kasireddy002@gmail.com>
Subject: See you tonight
Body:
Content-type: text/plain
Data length: 41
ERROR 2018-02-02 00:17:00,318 api_server.py:407] Exception while handling mail.Send()
Traceback (most recent call last):
File "C:\Program Files\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\api_server.py", line 375, in _handle_POST
api_response = _execute_request(request).Encode()
File "C:\Program Files\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\api_server.py", line 231, in _execute_request
make_request()
File "C:\Program Files\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\api_server.py", line 226, in make_request
request_id)
File "C:\Program Files\google-cloud-sdk\platform\google_appengine\google\appengine\api\apiproxy_stub.py", line 151, in MakeSyncCall
method(request, response)
File "C:\Program Files\google-cloud-sdk\platform\google_appengine\google\appengine\api\mail_stub.py", line 311, in _Send
self._SendSMTP(mime_message, smtp_lib)
File "C:\Program Files\google-cloud-sdk\platform\google_appengine\google\appengine\api\mail_stub.py", line 233, in _SendSMTP
smtp.sendmail(mime_message['From'], tos, mime_message.as_string())
File "C:\Python27\lib\smtplib.py", line 744, in sendmail
senderrs[each] = (code, resp)
TypeError: unhashable instance
从本地开发服务器和AppEngine
运行此代码package app
import (
"net/http"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
"google.golang.org/appengine/mail" )
func init() {
http.HandleFunc("/sendmail", handleIndex) }
func handleIndex(res http.ResponseWriter, req *http.Request) {
ctx := appengine.NewContext(req)
msg := &mail.Message{
Sender: "venkatanagarajas@gmail.com",
To: []string{"Srinadh <kasireddy002@gmail.com>"},
Subject: "See you tonight",
Body: "Don't forget our plans. Hark, 'til later.",
}
if err := mail.Send(ctx, msg); err != nil {
log.Errorf(ctx, "Alas, my user, the email failed to sendeth: %v", err)
} }
答案 0 :(得分:0)
GAE不在本地服务器上运行,您必须在本地配置SMTP并调用其方法
步骤: