本文整理汇总了Python中smtplib.SMTP_SSL.quit方法的典型用法代码示例。如果您正苦于以下问题:Python SMTP_SSL.quit方法的具体用法?Python SMTP_SSL.quit怎么用?Python SMTP_SSL.quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smtplib.SMTP_SSL
的用法示例。
在下文中一共展示了SMTP_SSL.quit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invite
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def invite(request):
f = InviteForm(request.POST)
movie=request.matchdict['movie_name']
if 'POST' == request.method and 'form.submitted' in request.params:
if request.session.get('logged_in', None):
to = request.POST['email']
me = ('[email protected]')
code = request.POST['code']
g = Groups()
g.code = code
g.movie_name = movie
g.movie_member = 0
DBSession.add(g)
msg = str (request.session['user_name'])+ " is inviting you to watch "+movie+" on date_user at time_user " + str(code)
msg = 'Subject: Movie Invitation \n\n%s' % (msg)
password= 'movies.junction'
# send it via gmail
s = SMTP_SSL('smtp.gmail.com', 465, timeout=10)
#s = smtplib.SMTP('smtp.live.com', 25) #4 hotmail
s.set_debuglevel(0)
#s = smtplib.SMTP('localhost')
try:
s.login(me, password)
s.sendmail(me, to.split(","), msg)
finally:
s.quit()
request.session.flash("Your message has been sent!")
return HTTPFound(location=request.route_url('home'))
return {'invite_form':f,'user_name':request.session['user_name'],'movie_name':movie}
示例2: contact_form
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def contact_form(request):
f = ContactForm(request.POST) # empty form initializes if not a POST request
if 'POST' == request.method and 'form.submitted' in request.params:
if f.validate():
#TODO: Do email sending here.
to = '[email protected],[email protected]'
user_from = request.POST['email']
me = ('[email protected]')
subject = request.POST['subject']
msg = str (request.POST['message']+"\n\nFrom : "+user_from)
msg = 'Subject: %s' % (subject) + ' \n\n%s' % (msg)
password= 'movies.junction'
# send it via gmail
s = SMTP_SSL('smtp.gmail.com', 465)
#s = smtplib.SMTP('smtp.live.com', 25) #4 hotmail
s.set_debuglevel(0)
#s = smtplib.SMTP('localhost')
try:
s.login(me, password)
s.sendmail(me, to.split(","), msg)
finally:
s.quit()
request.session.flash("Your message has been sent!")
return HTTPFound(location=request.route_url('home'))
return {'contact_form': f}
示例3: send_password_reset_email
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def send_password_reset_email(token, email, user_id):
SMTPserver = app.config.get('EMAIL_SMTP')
sender = app.config.get('ADMIN_USER')
destination = [email]
USERNAME = app.config.get('ADMIN_USER')
PASSWORD = app.config.get('ADMIN_USER_PASSWORD')
text_subtype = 'plain'
content="""\
We have received a password reset request for the account associated with this email. If you made this request, please use this token to reset your password:
"""+token.decode("utf8")
subject="Password reset requested"
msg = MIMEText(content, text_subtype)
msg['Subject']= subject
msg['From'] = sender
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(USERNAME, PASSWORD)
try:
conn.sendmail(sender, destination, msg.as_string())
finally:
conn.quit()
return ""
示例4: sent
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def sent(filepath):
from smtplib import SMTP_SSL
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders
import os
#filepath = "/path/to/file"
basename = os.path.basename(filepath)
address = 'adr'
address_to = "[email protected]"
# Compose attachment
part = MIMEBase('application', "octet-stream")
part.set_payload(open(filepath,"rb").read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % basename)
# Compose message
msg = MIMEMultipart()
msg['From'] = address
msg['To'] = address_to
msg.attach(part)
# Send mail
smtp = SMTP_SSL()
smtp.connect('smtp.yandex.ru')
smtp.login(address, 'password')
smtp.sendmail(address, address_to, msg.as_string())
smtp.quit()
示例5: _send
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def _send(self, email_addr, msg):
"""Deliver an email using SMTP
:param email_addr: recipient
:type email_addr: str.
:param msg: email text
:type msg: str.
"""
proto = self._conf["proto"]
assert proto in ("smtp", "starttls", "ssl"), "Incorrect protocol: %s" % proto
try:
if proto == "ssl":
log.debug("Setting up SSL")
session = SMTP_SSL(self._conf["fqdn"], self._conf["port"])
else:
session = SMTP(self._conf["fqdn"], self._conf["port"])
if proto == "starttls":
log.debug("Sending EHLO and STARTTLS")
session.ehlo()
session.starttls()
session.ehlo()
if self._conf["user"] is not None:
log.debug("Performing login")
session.login(self._conf["user"], self._conf["pass"])
log.debug("Sending")
session.sendmail(self.sender, email_addr, msg)
session.quit()
log.info("Email sent")
except Exception as e: # pragma: no cover
log.error("Error sending email: %s" % e, exc_info=True)
示例6: send
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def send(self, *args, **kwargs):
picture = kwargs.get('pic')
msg = MIMEMultipart()
msg['Charset'] = "UTF-8"
msg['Date'] = formatdate(localtime=True)
msg['From'] = self.login + '@' + '.'.join(self.smtp.split('.')[1:])
msg['Subject'] = "Détection d'un mouvement suspect"
msg['To'] = self.send_to
msg.attach(MIMEText('', 'html'))
part = MIMEBase('application', 'octet-stream')
fp = open(picture, 'rb')
part.set_payload(fp.read())
encode_base64(part)
part.add_header('Content-Disposition', 'attachment', filename=picture)
msg.attach(part)
try:
server = SMTP_SSL(self.smtp, self.port)
server.set_debuglevel(False)
server.ehlo
server.login(self.login, self.password)
try:
server.sendmail(self.From, self.send_to, msg.as_string())
finally:
server.quit()
except Exception as e:
logging.critical("Unable to send an email\n{0}".format(str(e)))
sys.exit(2)
示例7: mail_send
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def mail_send(self, subject, emailaddr, key, msg):
if self._limit:
self._clean_array()
epoch = time.time()
if not key in self._array:
self._array[key] = epoch
else:
ts = self._array.get(key)
if epoch - ts < self._timeout:
return self.RET_NOTAUTH
else:
self._array[key] = epoch
if self.DEBUG:
self._debug('new mail:')
self._debug('subject: %s' % (subject))
self._debug('addr: %s' % (emailaddr))
self._debug('key: %s' % (key))
self._debug('msg: %s' % (msg))
try:
mailserver = SMTP(self._addr)
mailserver.set_debuglevel(self._mail_debug)
mailserver.login(self._username, self._password)
date = datetime.datetime.now().strftime('%a, %d %b %Y %H:%M:%S %z')
msg = self.MAIL_MSG % (self._srcmail, emailaddr, subject, date, msg)
mailserver.sendmail(self._srcmail, emailaddr, msg)
mailserver.quit()
except Exception as msg:
self._error(str(msg))
return self.RET_ERR
return self.RET_SUCCESS
示例8: sendmail
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def sendmail(to_mails, message):
# Update settings
apply_db_settings(flask_app.flask_app)
mail = 'From: {}\nTo: {}\nSubject: {}\n\n{}'.format(
flask_app.flask_app.config.get('EMAIL_EMAIL_FROM'),
to_mails,
flask_app.flask_app.config.get('EMAIL_SUBJECT'),
message
).encode(encoding='utf-8')
server_str = '{}:{}'.format(flask_app.flask_app.config.get('EMAIL_HOST', '127.0.0.1'),
flask_app.flask_app.config.get('EMAIL_PORT', 25))
server = SMTP_SSL(server_str) if flask_app.flask_app.config.get('EMAIL_ENCRYPTION', 0) == 2 \
else SMTP(server_str)
if flask_app.flask_app.config.get('EMAIL_ENCRYPTION', 0) == 1:
server.starttls()
if flask_app.flask_app.config.get('EMAIL_AUTH', 0):
server.login(flask_app.flask_app.config.get('EMAIL_LOGIN'),
flask_app.flask_app.config.get('EMAIL_PASSWORD'))
server.sendmail(flask_app.flask_app.config.get('EMAIL_EMAIL_FROM'),
to_mails,
mail)
server.quit()
示例9: landing_customer_contacts
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def landing_customer_contacts(customer_email, customer_phone, customer_session):
"""
Функция отправки контактных данных полученных с лендинга.
:return:
"""
msg = email.MIMEMultipart.MIMEMultipart()
from_addr = "[email protected]"
to_addr = "[email protected], [email protected]"
msg['From'] = from_addr
msg['To'] = to_addr
text = "\tE-mail: %s \n\tТелефон: %s \n" % (customer_email, customer_phone)
text += "\tДата и время: %s \n" % datetime.datetime.now()
text += "Параметры сессии: \n "
for a,b in customer_session.items():
text += "\t%s : %s \n" % (a, b)
msg['Subject'] = Header("Контакты с лендинга Conversation parser", "utf8")
body = "Оставлены контакты. \n" + text
msg.preamble = "This is a multi-part message in MIME format."
msg.epilogue = "End of message"
msg.attach(email.MIMEText.MIMEText(body, "plain", "UTF-8"))
smtp = SMTP_SSL()
smtp.connect(smtp_server)
smtp.login(from_addr, "Cthutq123")
text = msg.as_string()
smtp.sendmail(from_addr, to_addr.split(","), text)
smtp.quit()
示例10: sendmail
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def sendmail(to_addrs, subject, text):
server = config.get('smtp_server')
use_tls = asbool(config.get('smtp_use_tls'))
username = config.get('smtp_username')
password = config.get('smtp_password')
from_addr = config.get('admin_email_from')
log.debug('Sending mail via %s' % server)
if use_tls:
s = SMTP_SSL()
else:
s = SMTP()
s.connect(server)
if username:
s.login(username, password)
msg = MIMEText(text, _charset='utf-8')
msg['From'] = from_addr
msg['Reply-To'] = from_addr
if isinstance(to_addrs, basestring):
msg['To'] = to_addrs
else:
msg['To'] = ', '.join(to_addrs)
msg['Subject'] = subject
s.sendmail(from_addr, to_addrs, msg.as_string())
s.quit()
示例11: _send
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def _send(self, email_addrs, msg):
proto = self._conf['proto']
assert proto in ('smtp', 'starttls', 'ssl'), \
"Incorrect protocol: %s" % proto
try:
if proto == 'ssl':
session = SMTP_SSL(self._conf['fqdn'], self._conf['port'])
else:
session = SMTP(self._conf['fqdn'], self._conf['port'])
if proto == 'starttls':
session.ehlo()
session.starttls()
session.ehlo()
if self._conf['user'] is not None:
session.login(self._conf['user'], self._conf['pass'])
session.sendmail(self.sender, email_addrs, msg)
session.quit()
except Exception as e: # pragma: no cover
''' '''
print str(e)
示例12: emailFile
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def emailFile( textfile, subject):
if not config.SEND_EMAIL:
return
try:
fp = open(textfile, 'rb')
msg = MIMEText(fp.read())
fp.close()
me = os.environ['FASTMAIL_USER']
password = os.environ['FASTMAIL_PASSWORD']
smtp = os.environ['FASTMAIL_SMTP']
msg['Subject'] = subject
msg['From'] = me
msg['To'] = me
if verbose:
print "sending email to ", me
# Send the message via our own SMTP server, but don't include the envelope header.
s = SMTP(smtp)
s.login(me, password)
s.sendmail(me, [me], msg.as_string())
s.quit()
except Exception as e:
print "exception sending email exception", e
示例13: testsettings
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def testsettings(host, port, login, password):
host = host.encode('utf-8')
port = int(port)
login = login.encode('utf-8')
password = password.encode('utf-8')
try: # SSL
smtp = SMTP_SSL(host, port)
ret, _ = smtp.login(login, password)
smtp.quit()
if ret is 235: # 2.7.0 Authentication successful
return True
except (ssl.SSLError, SMTPException):
pass
try: # STARTTLS or plaintext
smtp = SMTP(host, port)
smtp.starttls()
smtp.ehlo()
ret, _ = smtp.login(login, password)
smtp.quit()
if ret is 235:
return True
except SMTPException:
pass
return False
示例14: sendMessage
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def sendMessage(self, sender, password, recipient, subject, body, attachmentFilenames=[]):
if type(attachmentFilenames) != list:
attachmentFilenames = [attachmentFilenames]
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = recipient
msg['Date'] = formatdate(localtime=True)
msg.attach(MIMEText(body, 'html'))
for filename in attachmentFilenames:
part = MIMEBase('application', "octet-stream")
part.set_payload(open(filename, "rb").read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % basename(filename))
msg.attach(part)
self.out.put("connecting...")
mailServer = SMTP_SSL(self.smtpHost, 465)
mailServer.ehlo()
self.out.put("logging in...")
mailServer.login(sender, password)
self.out.put("sending...")
mailServer.sendmail(sender, recipient, msg.as_string()) # raise if email is not sent
mailServer.quit()
self.out.put("done.")
示例15: send_email
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import quit [as 别名]
def send_email(address, token):
"""Send the verification e-mail."""
c = get_config()
link = url_for(".verify", token=token, _external=True)
# Prepare the e-mail message.
msg = MIMEMultipart("alternative")
msg["Subject"] = "Verify your account for the [____] Train"
msg["From"] = "[____] Train <{}>".format(c.mail.sender)
msg["To"] = address
html = render_template("activate_email.html", link=link)
text = text_verify(link)
part1 = MIMEText(text.encode("UTF-8"), "plain", "UTF-8")
part2 = MIMEText(html.encode("UTF-8"), "html", "UTF-8")
# Attach
msg.attach(part1)
msg.attach(part2)
# Send email
smtp = None
if c.mail.ssl:
smtp = SMTP_SSL(c.mail.host)
else:
smtp = SMTP(c.mail.host)
if c.mail.username and c.mail.password:
smtp.login(c.mail.username, c.mail.password)
smtp.sendmail(msg["From"], address, msg.as_string())
smtp.quit()