Python 删除电子邮件地址的名称部分-“删除”;约翰·史密斯<;jsmith@email.com&燃气轮机&引用;
“我的应用程序引擎”应用程序接收电子邮件并将发件人的电子邮件地址添加到我的数据存储中,但其格式如下:Python 删除电子邮件地址的名称部分-“删除”;约翰·史密斯<;jsmith@email.com&燃气轮机&引用;,python,Python,“我的应用程序引擎”应用程序接收电子邮件并将发件人的电子邮件地址添加到我的数据存储中,但其格式如下: John Smith 是否要从该字符串中去掉名称和括号,使其只读取jsmith@email.com 这是我的传入邮件处理程序(如果有帮助): import webapp2 import logging from google.appengine.ext.webapp import mail_handlers from google.appengine.api import mail import
John Smith
是否要从该字符串中去掉名称和括号,使其只读取jsmith@email.com
这是我的传入邮件处理程序(如果有帮助):
import webapp2
import logging
from google.appengine.ext.webapp import mail_handlers
from google.appengine.api import mail
import os
from main import WorkRequest
class IncomingMailHandler(mail_handlers.InboundMailHandler):
def receive(self, message):
(encoding, payload) = list(message.bodies(content_type='text/plain'))[0]
body_text = payload.decode()
logging.info('Received email message from %s, subject "%s": %s' %
(message.sender, message.subject, body_text))
logging.info (message.sender)
logging.info(message.subject)
logging.info(body_text)
wr = WorkRequest()
wr.email = message.sender
wr.userId = None
wr.title = message.subject
wr.content = body_text
wr.status = "OPEN"
wr.submission_type = "EMAIL"
wr.assigned_to = "UNASSIGNED"
wr.put()
application = webapp2.WSGIApplication([('/_ah/mail/.+', IncomingMailHandler)],debug=True)
请尝试添加此代码:
email= "John Smith <jsmith@email.com>"
def changeEmail(email):
"""
A vary simple method to modify a email to the wanted email address.
input "John Smith <jsmith@email.com>" -> output "jsmith@email.com"
"""
email=email.split("<") #email= ['John Smith ', 'jsmith@email.com>'
email=email[1] # email=jsmith@email.com> . need to remove >
email=email[:-1] # email= jsmith@email.com
return email
email= changeEmail(email) #email= jsmith@email.com
email=“约翰·史密斯”
def更改电子邮件(电子邮件):
"""
将电子邮件修改为所需电子邮件地址的简单方法。
输入“John Smith”->输出jsmith@email.com"
"""
email=email.split("试着检查输入的字符串是否有这种格式,以及它是否只提取了<和>之间的部分。你可以使用正则表达式:谢谢,我会读一读。还有为什么我的问题被否决了?为什么这个网站让初学者觉得在我试着学习的时候他们问了一个愚蠢的问题?我没有否决,but我想不管是谁都想告诉你A)你没有努力解决你的问题,B)你提供的代码与你的问题无关。您试图从另一个字符串中提取一个字符串,邮件处理程序的工作方式与此上下文无关。