使用应用程序发明者应用程序从谷歌应用程序引擎发送邮件

发布于 2024-12-04 12:57:40 字数 2522 浏览 2 评论 0原文

在应用程序发明者中使用 Shival 狼 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)

我希望就是这样!对此不熟悉。

Using Shival wolfs WolfWebEmail2 in app inventor to send mail via Google app engine and nothing arriving in recipient email.

need to confirm if my code is correct.

not showing any errors on app engine.

Does this look correct for command to run webapp?

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

Think i have got a bit of small keyboard large finger syndrome.

Many thanks in advance.

OK Zig. Many thanks. Here it is

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)

I hope thats it! new to this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月蹉跎了容颜 2024-12-11 12:58:49

您能给我们展示一下 sendemail 功能吗?

编辑

message.sender = EmailFrom

EmailFrom 在哪里?

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

首先尝试运行此命令 -

message = mail.EmailMessage(sender="[email protected]",
                            subject="Testing")
message.to = "[email protected]"
message.body = "This is the body!"
message.send()

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

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

Can you show us the sendemail function?

EDIT

message.sender = EmailFrom

Where is EmailFrom?

Try removing all the validations and check if the email gets sent.

First try running this-

message = mail.EmailMessage(sender="[email protected]",
                            subject="Testing")
message.to = "[email protected]"
message.body = "This is the body!"
message.send()

Change both email addresses to your email.

If it works then check the validation and other parts one at a time.

岁吢 2024-12-11 12:58:27

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

if __name__ == '__main__':
  main()

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

You've left out the last part of the boiplerplate:

if __name__ == '__main__':
  main()

Without it, the first request to each instance won't be processed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文