本文整理汇总了Python中smtplib.SMTP.ehlo_or_helo_if_needed方法的典型用法代码示例。如果您正苦于以下问题:Python SMTP.ehlo_or_helo_if_needed方法的具体用法?Python SMTP.ehlo_or_helo_if_needed怎么用?Python SMTP.ehlo_or_helo_if_needed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smtplib.SMTP
的用法示例。
在下文中一共展示了SMTP.ehlo_or_helo_if_needed方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: flush
# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
def flush(self):
from smtplib import SMTP
import settings, logging
if not self.messages:
return
msg = 'To: ' + settings.to_addr + '\n'
msg += 'From: ' + settings.from_addr + '\n'
if len(self.messages) == 1:
msg += 'Subject: mmonitor: ' + self.messages[0][:200] + '\n'
else:
msg += 'Subject: mmonitor: multiple notices\n'
msg += '\n\n'
msg += '\n'.join(self.messages)
msg += '\n\n'
logging.info('sending mail:\n%s', '\n'.join(self.messages))
smtp = SMTP(settings.smtp_host, settings.smtp_port)
if settings.smtp_tls:
smtp.starttls()
smtp.ehlo_or_helo_if_needed()
if settings.smtp_user:
smtp.login(settings.smtp_user, settings.smtp_password)
smtp.sendmail(settings.from_addr, settings.to_addr, msg)
smtp.close()
self.messages = []
示例2: connect
# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
def connect(self):
"""Connect the SMTP Server"""
smtp = SMTP(smart_str(self.host), int(self.port))
smtp.ehlo_or_helo_if_needed()
if self.tls:
smtp.starttls()
smtp.ehlo_or_helo_if_needed()
if self.user or self.password:
smtp.login(smart_str(self.user), smart_str(self.password))
return smtp
示例3: handle
# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
def handle(to='[email protected]', sender = '[email protected]', body = 'mierda'):
"""
Forward a message via an authenticated SMTP connection with
starttls.
"""
conn = SMTP(SMTP_HOST, 25, 'localhost')
conn.starttls()
conn.ehlo_or_helo_if_needed()
conn.login(SMTP_USERNAME, SMTP_PASSWORD)
conn.sendmail(sender, to, body)
conn.quit()
示例4: _prompt_smtp_data
# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
def _prompt_smtp_data(self, dev=False):
def _get_default_smtp(custom_host=None):
if custom_host:
candidates = [(custom_host, 25), (custom_host, 587)]
else:
candidates = [('127.0.0.1', 25), ('127.0.0.1', 587)]
if dev:
candidates.insert(0, (custom_host or '127.0.0.1', 1025))
for host, port in candidates:
try:
SMTP(host, port, timeout=3).close()
except Exception:
continue
return host, port
return '', ''
first = True
default_smtp_host, default_smtp_port = _get_default_smtp()
smtp_user = ''
while True:
smtp_host = _prompt('SMTP host', default=default_smtp_host,
help=('Indico needs an SMTP server to send emails.' if first else None))
if smtp_host != default_smtp_host:
default_smtp_port = _get_default_smtp(smtp_host)[1]
smtp_port = int(_prompt('SMTP port', default=unicode(default_smtp_port or 25)))
smtp_user = _prompt('SMTP username', default=smtp_user, required=False,
help=('If your SMTP server requires authentication, '
'enter the username now.' if first else None))
smtp_password = _prompt('SMTP password', password=True) if smtp_user else ''
first = False
# Test whether we can connect
try:
smtp = SMTP(smtp_host, smtp_port, timeout=10)
smtp.ehlo_or_helo_if_needed()
if smtp_user and smtp_password:
smtp.starttls()
smtp.login(smtp_user, smtp_password)
smtp.quit()
except Exception as exc:
_warn('SMTP connection failed: ' + unicode(exc))
if not click.confirm('Keep these settings anyway?'):
default_smtp_host = smtp_host
default_smtp_port = smtp_port
continue
self.smtp_host = smtp_host
self.smtp_port = smtp_port
self.smtp_user = smtp_user
self.smtp_password = smtp_password
break
示例5: send_error
# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
def send_error(ex, config):
body = 'Error type: ' + type(ex).__name__ + '\nMessage: '
for arg in ex.args:
body += arg + '\n'
msg = MIMEText(body)
msg['Subject'] = 'name.com Update Error'
msg['From'] = 'donotreply'
msg['To'] = config['email']
server = SMTP(config['smtp'])
server.ehlo_or_helo_if_needed()
server.starttls()
server.login(config['smtpuser'], config['smtppassword'])
server.send_message(msg)
server.quit()
示例6: _conectar
# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import ehlo_or_helo_if_needed [as 别名]
def _conectar(self):
"""
Rutina de conexión a un servidor SMTP.
:return:
"""
try:
# Conexion con el servidor smtp y procesos para el protocolo.
server = SMTP(self.smtp_host, self.smtp_port)
server.ehlo_or_helo_if_needed() # helo en serv no-ESMTP
server.starttls() # Si servidor no lo habilita, yerra.
server.ehlo_or_helo_if_needed()
server.login(self.email_origen, self.passw)
self._estadoconexion(nuevo_serv=server)
except SMTPException as smtpe:
raise
except:
raise