2

在应用程序发明者中使用 Shival wolfs WolfWebEmail2 通过 Google 应用程序引擎发送邮件,但收件人电子邮件中没有任何内容。

需要确认我的代码是否正确。

没有在应用引擎上显示任何错误。

这对于运行 webapp 的命令看起来是否正确?

application = webapp.WSGIApplication([('/', MainPage), ('/sendemail', sendemail), ('/attach', attachfile)], debug=True)
def main():
  run_wsgi_app(application)

想想我有点小键盘大手指综合症。

提前谢谢了。

好的齐格。非常感谢。这里是

class sendemail(webapp.RequestHandler):

  def process_email(self, data):
outvalue=""
ValidData = False
logging.info("data: %s" %data)
details=data.split("|||")
data = "\"%s\"" %data
if len(details) == 5 or len(details) == 7:
  message = mail.EmailMessage()
  message.sender = EmailFrom
  NewAuthKey = details[0]
  EmailTo = details[1]
  EmailSubject = details[2]
  EmailBody = details[3]
  EmailBody = EmailBody.replace("\\t","\t")
  if details[4].lower()=="yes" and len(details) == 7:
    filename=details[5];
    file_id=details[6];
  ValidData = True

if ValidData:
  if NewAuthKey == AuthKey:
    logging.info("Auth Key Valid")
  else:
    logging.info("Auth Key does not Match")
    outvalue = "Auth Key is Invalid"
    ValidData = False

if ValidData:
  if mail.is_email_valid(EmailTo):
    message.to = EmailTo
  else:
    logging.info("Email Address for TO Address is Invalid")
    outvalue = "Email Address for TO Address is Invalid"
    ValidData = False

if ValidData:
  if len(EmailBody) > 0 and len(EmailSubject) > 0:
    message.subject = EmailSubject
    message.body = EmailBody
  else:
    logging.info("Subject or Body was Empty")
    outvalue = "Subject or Body was left Empty"
    ValidData = False

if ValidData:
  if details[4].lower()=="yes":
    try:
       filedata = db.GqlQuery("SELECT * FROM emailattach WHERE id = :1 LIMIT 1",file_id).get()
       if filedata:
         message.attachments = [(filename, filedata.blob)]
    except Exception, message:
      ValidData = False
      logging.info("Could not attach file:\n\n "+str(message))
      outvalue = "Could not attach file:\n\n "+str(message)

if ValidData:
  try:
    message.send()
    logging.info("Email Sent")
    outvalue = "Email Sent"
if details[4].lower()=="yes":   ##delete the file once emailed
      key = db.GqlQuery("SELECT __key__ FROM emailattach where id = :1", file_id).get()
      if key:
        db.run_in_transaction(dbSafeDelete,key)

  except Exception, message:
    logging.info(message)
    outvalue = str(message)

self.response.out.write(outvalue)

我希望就是这样!对此很陌生。

4

2 回答 2

0

您遗漏了样板的最后一部分:

if __name__ == '__main__':
  main()

没有它,将不会处理对每个实例的第一个请求。

于 2011-09-14T00:00:17.750 回答
0

你能告诉我们sendemail功能吗?

编辑

message.sender = EmailFrom

EmailFrom 在哪里?

尝试删除所有验证并检查电子邮件是否已发送。

首先尝试运行这个-

message = mail.EmailMessage(sender="you@domain.com",
                            subject="Testing")
message.to = "you@domain.com"
message.body = "This is the body!"
message.send()

将两个电子邮件地址都更改为您的电子邮件。

如果它有效,则一次检查验证和其他部分。

于 2011-09-14T19:44:13.250 回答