本文整理汇总了Python中smtplib.quoteaddr函数的典型用法代码示例。如果您正苦于以下问题:Python quoteaddr函数的具体用法?Python quoteaddr怎么用?Python quoteaddr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quoteaddr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
def run(self, check=True):
import smtplib
from MaKaC.webinterface.mail import GenericMailer, GenericNotification
# prepare the mail
send = self._prepare(check=check)
# _prepare decided we shouldn't send the mail?
if not send:
return
addrs = [smtplib.quoteaddr(x) for x in self.toAddr]
ccaddrs = [smtplib.quoteaddr(x) for x in self.ccAddr]
if len(addrs) + len(ccaddrs) == 0:
self.getLogger().warning("Attention: mail contains no recipients!")
else:
self.getLogger().info("Sending mail To: %s, CC: %s" % (addrs, ccaddrs))
for user in self.toUser:
addrs.append(smtplib.quoteaddr(user.getEmail()))
GenericMailer.send(
GenericNotification(
{
"fromAddr": self.fromAddr,
"toList": addrs,
"ccList": ccaddrs,
"subject": self.subject,
"body": self.text,
}
)
)
开发者ID:bubbas,项目名称:indico,代码行数:33,代码来源:tasks.py
示例2: run
def run(self, check=True):
import smtplib
from MaKaC.webinterface.mail import GenericMailer, GenericNotification
# prepare the mail
send = self._prepare(check=check)
# _prepare decided we shouldn't send the mail?
if not send:
return
# just in case some ill-behaved code generates empty addresses
addrs = list(smtplib.quoteaddr(x) for x in self.toAddr if x)
ccaddrs = list(smtplib.quoteaddr(x) for x in self.ccAddr if x)
if len(addrs) + len(ccaddrs) == 0:
self.getLogger().warning("Attention: no recipients, mail won't be sent")
else:
self.getLogger().info("Sending mail To: %s, CC: %s" % (addrs, ccaddrs))
for user in self.toUser:
addrs.append(smtplib.quoteaddr(user.getEmail()))
if addrs or ccaddrs:
GenericMailer.send(GenericNotification({"fromAddr": self.fromAddr,
"toList": addrs,
"ccList": ccaddrs,
"subject": self.subject,
"body": self.text }))
开发者ID:pferreir,项目名称:indico-backup,代码行数:29,代码来源:__init__.py
示例3: run
def run(self):
addrs = []
ccaddrs = []
for addr in self.toAddr:
addrs.append(smtplib.quoteaddr(addr))
for ccaddr in self.ccAddr:
ccaddrs.append(smtplib.quoteaddr(ccaddr))
for user in self.toUser:
addrs.append(smtplib.quoteaddr(user.getEmail()))
maildata = { "fromAddr": self.fromAddr, "toList": addrs, "ccList": ccaddrs, "subject": self.subject, "body": self.text }
GenericMailer.send(GenericNotification(maildata))
开发者ID:bubbas,项目名称:indico,代码行数:11,代码来源:timerExec.py
示例4: _sendmail
def _sendmail(message=None, debug=False, timeout=10, mongo_settings=None, sleeping=None, smtp_rcpt=None, **kwargs):
host, port = utils.get_free_port()
with smtp_server(host=host, port=port, mongo_settings=mongo_settings, timeout=timeout, **kwargs) as server:
assert server.col.count() == 0
s = smtp_client(host, port, debug=debug)
(code, msg) = s.ehlo()
assert code == 250
if sleeping:
gevent.sleep(sleeping)
xforward = {
'ADDR': '192.168.1.1',
'NAME': 'mail.local.net',
'HELO': 'local.net',
}
(code, msg) = s.docmd('XFORWARD', 'ADDR=%(ADDR)s NAME=%(NAME)s HELO=%(HELO)s' % xforward)
assert code == 250
froms = message.get_all('X-Envelope-From', [])
if not smtp_rcpt:
_recipients = message.get_all('X-Envelope-To', [])
recipients = getaddresses(_recipients)
else:
recipients = [smtp_rcpt]
message_string = message.as_string()
(code, msg) = s.mail(smtplib.quoteaddr(froms[0]), ["size=%s" % len(message_string)])
assert code == 250
for recipient in recipients:
(code, msg) = s.docmd('RCPT TO:', smtplib.quoteaddr(recipient))
assert code == 250
(code, msg) = s.data(message_string)
assert code == 250
(code, msg) = s.docmd('quit')
assert code == 221
return server
开发者ID:radical-software,项目名称:mongo-mail-server,代码行数:49,代码来源:test_server.py
示例5: rcpt
def rcpt(self, recip, options=[]):
"""SMTP 'rcpt' command -- indicates 1 recipient for this mail."""
optionlist = ''
if options and self.does_esmtp:
optionlist = ' ' + ' '.join(options)
code, msg = yield self.docmd(b"rcpt", ("TO:%s%s" % (smtplib.quoteaddr(recip), optionlist)).encode('ascii'))
raise gen.Return((code, msg))
开发者ID:Rustem,项目名称:tornado-smtpclient,代码行数:7,代码来源:client.py
示例6: rcpt
async def rcpt(self, recipient, options=None):
"""
Sends a SMTP 'RCPT' command. - Indicates a recipient for the e-mail.
For further details, please check out `RFC 5321 § 4.1.1.3`_ and
`§ 3.3`_.
Args:
recipient (str): E-mail address of one recipient.
options (list of str or None, optional): Additional options to send
along with the *RCPT* command.
Raises:
ConnectionResetError: If the connection with the server is
unexpectedely lost.
SMTPCommandFailedError: If the RCPT command fails.
Returns:
(int, str): A (code, message) 2-tuple containing the server
response.
.. _`RFC 5321 § 4.1.1.3`: https://tools.ietf.org/html/rfc5321#section-4.1.1.3
.. _`§ 3.3`: https://tools.ietf.org/html/rfc5321#section-3.3
"""
if options is None:
options = []
to_addr = "TO:{}".format(quoteaddr(recipient))
code, message = await self.do_cmd("RCPT", to_addr, *options)
return code, message
开发者ID:hwmrocker,项目名称:smtplibaio,代码行数:31,代码来源:smtp.py
示例7: mail
async def mail(self, sender, options=None):
"""
Sends a SMTP 'MAIL' command. - Starts the mail transfer session.
For further details, please check out `RFC 5321 § 4.1.1.2`_ and
`§ 3.3`_.
Args:
sender (str): Sender mailbox (used as reverse-path).
options (list of str or None, optional): Additional options to send
along with the *MAIL* command.
Raises:
ConnectionResetError: If the connection with the server is
unexpectedely lost.
SMTPCommandFailedError: If the MAIL command fails.
Returns:
(int, str): A (code, message) 2-tuple containing the server
response.
.. _`RFC 5321 § 4.1.1.2`: https://tools.ietf.org/html/rfc5321#section-4.1.1.2
.. _`§ 3.3`: https://tools.ietf.org/html/rfc5321#section-3.3
"""
if options is None:
options = []
from_addr = "FROM:{}".format(quoteaddr(sender))
code, message = await self.do_cmd("MAIL", from_addr, *options)
return code, message
开发者ID:hwmrocker,项目名称:smtplibaio,代码行数:31,代码来源:smtp.py
示例8: send_emails
def send_emails(self, from_email, emails, content):
""" Use /usr/bin/sendmail or fallback to smtplib.
"""
if len(emails) == 0: # Nobody to send to - it happens
return RETURN_CODES['EX_OK']
try:
# This should be secure check:
# http://docs.python.org/library/subprocess.html#using-the-subprocess-module
# It turns out that sendmail splits the addresses on space,
# eventhough there is one address per argument. See RFC5322 section
# 3.4 Try: /usr/sbin/sendmail 'soren.roug @eea.europa.eu' and it
# will complain about the address. We therefore clean them with
# smtplib.quoteaddr
quotedemails = map(smtplib.quoteaddr, emails)
ps = Popen([self.sendmail_path,
'-f',
smtplib.quoteaddr(from_email),
'--'] + quotedemails,
stdin=PIPE)
ps.stdin.write(content)
ps.stdin.flush()
ps.stdin.close()
return_code = ps.wait()
if return_code in (RETURN_CODES['EX_OK'],
RETURN_CODES['EX_TEMPFAIL']):
log.debug("Sent emails to %r", emails)
return RETURN_CODES['EX_OK']
else:
log.error("Failed to send emails using sendmail to %r. "
"/usr/sbin/sendmail exited with code %d", emails,
return_code)
return return_code
except OSError: # fallback to smtplib
# Since this is the same mailer we use localhost
# Smtplib quotes the addresses internally
log.exception("Cannot use sendmail program. Falling back to "
"smtplib.")
log.warning(
"If the smtp connection fails some emails will be lost")
smtp = smtplib.SMTP('localhost')
try:
try:
smtp.sendmail(from_email, emails, content)
log.debug("Sent emails to %r", emails)
except smtplib.SMTPException:
log.exception("SMTP Error")
log.error(
"Failed to send emails using smtplib to %r", emails)
return RETURN_CODES['EX_PROTOCOL']
except:
log.exception("Unknown smtplib error")
return RETURN_CODES['EX_UNAVAILABLE']
finally:
try:
smtp.quit()
except:
pass
return RETURN_CODES['EX_OK']
开发者ID:eea,项目名称:eea.mailexpander,代码行数:59,代码来源:expander.py
示例9: testVRFY
def testVRFY(self):
smtp = smtplib.SMTP(HOST, self.port, local_hostname="localhost", timeout=15)
for email, name in sim_users.items():
expected_known = (250, bytes("%s %s" % (name, smtplib.quoteaddr(email)), "ascii"))
self.assertEqual(smtp.vrfy(email), expected_known)
u = "[email protected]"
expected_unknown = (550, ("No such user: %s" % u).encode("ascii"))
self.assertEqual(smtp.vrfy(u), expected_unknown)
smtp.quit()
开发者ID:pykomke,项目名称:Kurz_Python_KE,代码行数:11,代码来源:test_smtplib.py
示例10: validateEmailDomain
def validateEmailDomain(toEmail):
toDomain = smtplib.quoteaddr(toEmail).split('@')[-1][0:-1]
VALIDATED_DOMAINS = ('localhost', 'localhost.localdomain')
# basically if we don't implicitly know this domain,
# and we can't look up the DNS entry of the MX
# use gethostbyname to validate the email address
try:
if not ((toDomain in VALIDATED_DOMAINS) or digMX(toDomain)):
socket.gethostbyname(toDomain)
except (socket.gaierror, dns.resolver.NXDOMAIN):
raise MailError("Email could not be sent: Bad domain name.")
开发者ID:pombredanne,项目名称:mint,代码行数:11,代码来源:maillib.py
示例11: smtp_EXPN
def smtp_EXPN(self, arg):
list_name = email.utils.parseaddr(arg)[1].lower()
if list_name in sim_lists:
user_list = sim_lists[list_name]
for n, user_email in enumerate(user_list):
quoted_addr = smtplib.quoteaddr(user_email)
if n < len(user_list) - 1:
self.push("250-%s %s" % (sim_users[user_email], quoted_addr))
else:
self.push("250 %s %s" % (sim_users[user_email], quoted_addr))
else:
self.push("550 No access for you!")
开发者ID:JianchengZh,项目名称:gevent,代码行数:12,代码来源:test_smtplib.py
示例12: smtp_EXPN
def smtp_EXPN(self, arg):
list_name = arg.lower()
if list_name in sim_lists:
user_list = sim_lists[list_name]
for n, user_email in enumerate(user_list):
quoted_addr = smtplib.quoteaddr(user_email)
if n < len(user_list) - 1:
self.push('250-%s %s' % (sim_users[user_email], quoted_addr))
else:
self.push('250 %s %s' % (sim_users[user_email], quoted_addr))
else:
self.push('550 No access for you!')
开发者ID:CCNITSilchar,项目名称:cpython,代码行数:12,代码来源:test_smtplib.py
示例13: testVRFY
def testVRFY(self):
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
for addr_spec, name in sim_users.items():
expected_known = (250, bytes('%s %s' %
(name, smtplib.quoteaddr(addr_spec)),
"ascii"))
self.assertEqual(smtp.vrfy(addr_spec), expected_known)
u = '[email protected]'
expected_unknown = (550, ('No such user: %s' % u).encode('ascii'))
self.assertEqual(smtp.vrfy(u), expected_unknown)
smtp.quit()
开发者ID:CCNITSilchar,项目名称:cpython,代码行数:13,代码来源:test_smtplib.py
示例14: testEXPN
def testEXPN(self):
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
for listname, members in sim_lists.items():
users = []
for m in members:
users.append('%s %s' % (sim_users[m], smtplib.quoteaddr(m)))
expected_known = (250, bytes('\n'.join(users), "ascii"))
self.assertEqual(smtp.expn(listname), expected_known)
u = 'PSU-Members-List'
expected_unknown = (550, b'No access for you!')
self.assertEqual(smtp.expn(u), expected_unknown)
smtp.quit()
开发者ID:CCNITSilchar,项目名称:cpython,代码行数:14,代码来源:test_smtplib.py
示例15: testEXPN
def testEXPN(self):
smtp = smtplib.SMTP(HOST, self.port, local_hostname="localhost", timeout=15)
for listname, members in sim_lists.items():
users = []
for m in members:
users.append("%s %s" % (sim_users[m], smtplib.quoteaddr(m)))
expected_known = (250, "\n".join(users))
self.assertEqual(smtp.expn(listname), expected_known)
u = "PSU-Members-List"
expected_unknown = (550, "No access for you!")
self.assertEqual(smtp.expn(u), expected_unknown)
smtp.quit()
开发者ID:van7hu,项目名称:fanca,代码行数:14,代码来源:test_smtplib.py
示例16: _mongodb_verify
def _mongodb_verify(message=None, col=None, fs=None, debug=False):
froms = message.get_all('X-Envelope-From', [])
doc = col.find_one()
assert doc['sender'] == smtplib.quoteaddr(froms[0])[1:-1]
msg = utils.message_from_string(uncompress(fs.get(doc['message']).read()))
if debug:
print("")
print("------------------------------------------------------------")
print(message.as_string())
print("------------------------------------------------------------")
return doc, msg
开发者ID:radical-software,项目名称:mongo-mail-server,代码行数:17,代码来源:test_server.py
示例17: rcpt
def rcpt(self, to_addr, options):
'''
一个异步的rcpt命令,发送rcpt TO 收件者地址
'''
# 构造rcpt命令
rcpt_str = 'rcpt TO:{0} {1}'.format(
smtplib.quoteaddr(to_addr),
b' '.join(options),
).strip().encode('ascii')
code, responses = yield self.send(rcpt_str)
if code != '250' and code != '251':
if code == '421':
self.close()
else:
yield self.rset()
raise smtplib.SMTPSenderRefused(code, responses, to_addr)
raise gen.Return((code, responses))
开发者ID:windworship,项目名称:tornado_email,代码行数:19,代码来源:client.py
示例18: mail
def mail(self, from_addr, options):
'''
一个异步的mail命令,发送mail FROM 发送者地址
'''
# 构造发送命令
send_str = 'mail FROM:{0} {1}'.format(
smtplib.quoteaddr(from_addr),
b' '.join(options),
).strip().encode('ascii')
code, responses = yield self.send(send_str)
if code != '250':
if code == '421':
self.close()
else:
yield self.rset()
raise smtplib.SMTPSenderRefused(code, responses, from_addr)
raise gen.Return((code, responses))
开发者ID:windworship,项目名称:tornado_email,代码行数:19,代码来源:client.py
示例19: rcpt
def rcpt(self, recip, options=[]):
optionlist = ''
if options and self.does_esmtp:
optionlist = ' ' + string.join(options, ' ')
self.putcmd('rcpt', 'TO:%s%s' % (smtplib.quoteaddr(recip), optionlist))
return self.getreply()
开发者ID:medfreeman,项目名称:tmda-fork,代码行数:6,代码来源:LMTP.py
示例20: mail
def mail(self, sender, options=[]):
optionlist = ""
if options and self.does_esmtp:
optionlist = " " + " ".join(options)
(code, msg) = yield self.docmd(b"mail", ("FROM:%s%s" % (smtplib.quoteaddr(sender), optionlist)).encode("ascii"))
return (code, msg)
开发者ID:jhm9318,项目名称:tornado-smtpclient,代码行数:6,代码来源:client.py
注:本文中的smtplib.quoteaddr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论