本文整理汇总了Python中smtplib.SMTP_SSL.set_debuglevel方法的典型用法代码示例。如果您正苦于以下问题:Python SMTP_SSL.set_debuglevel方法的具体用法?Python SMTP_SSL.set_debuglevel怎么用?Python SMTP_SSL.set_debuglevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smtplib.SMTP_SSL
的用法示例。
在下文中一共展示了SMTP_SSL.set_debuglevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_email
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def send_email(content):
if content == "":
return False
destination = [DESTINATION]
# typical values for text_subtype are plain, html, xml
text_subtype = 'plain'
from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)
from email.mime.text import MIMEText
try:
msg = MIMEText(content, text_subtype, "utf-8")
msg['Subject'] = SUBJECT_EMAIL
msg['From'] = YA_USER
msg['To'] = DESTINATION
conn = SMTP(SMTP_SERVER)
conn.set_debuglevel(False)
conn.login(YA_USER, YA_PASS)
stat = False
try:
conn.sendmail(YA_USER, destination, msg.as_string())
stat = True
finally:
conn.close()
except Exception, exc:
pass
示例2: SendMail
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def SendMail(self):
USERNAME = "[email protected]"
PASSWORD = "YOURPASSWORD"
SMTPserver = 'smtp.YOURMAIL.com'
for permalink in self.commentswithtext:
body = self.commentswithtext[permalink]
if body[:len(self.breakstring)] != self.breakstring:
content = "FYI - " + permalink + """
""" + self.commentswithtext[permalink] + """
Thanks!
"""
content = content.encode('utf-8')
text_subtype = 'plain'
msg = MIMEText(content,'plain','utf-8')
msg['Subject']= "New Reddit Comment"
msg['From'] = "[email protected]"
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(USERNAME, PASSWORD)
try:
print("Sending Mail -- " + permalink)
conn.sendmail(msg['From'],msg['From'], msg.as_string())
finally:
conn.close()
# Mark that we've now sent this message
self.commentswithtext[permalink] = self.breakstring + str( int(time.time()) )
示例3: EmailConnection
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
class EmailConnection(object):
def __init__(self, sender, server, port, username, password, debug=False):
self.sender = sender
self.smtp = SMTP(server, port)
self.smtp.login(username, password)
self.smtp.set_debuglevel(False)
self.debug = debug
def send(self, sendto, subject, message):
if isinstance(sendto, basestring):
sendto = [sendto]
for to in sendto:
msg = MIMEText(message, "plain")
msg["Subject"] = subject
msg["To"] = to
msg["From"] = self.sender
if not self.debug:
try:
self.smtp.sendmail(self.sender, [to], msg.as_string())
except:
pass
else:
print msg.as_string()
def __del__(self):
self.smtp.close()
示例4: contact_form
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [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}
示例5: invite
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [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}
示例6: SendingEmail
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def SendingEmail(email,password,message,date):
SMTPserver = 'smtp.gmail.com'
sender = email
receivers = ['[email protected]','[email protected]']
# typical values for text_subtype are plain, html, xml
text_subtype = 'plain'
content = message
subject="Bluetooth Data Daily Report: %s" % (date)
USERNAME = email
PASSWORD = password
try:
msg = MIMEText(content, text_subtype)
msg['Subject']= subject
msg['From'] = sender # some SMTP servers will do this automatically, not all
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(USERNAME, PASSWORD)
try:
conn.sendmail(sender, receivers, msg.as_string())
finally:
conn.close()
except Exception, exc:
sys.exit( "mail failed; %s" % str(exc) ) # give a error message
示例7: send_token
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def send_token(token, address, server, username, password):
content = "Dein Token fuer den Zugang zum OpenLab ist da:\n\n"
content += "\t" + token + "\n\n"
content += "Nutze diese Links:\n"
content += "- Tuer oeffnen: https://labctl.ffa/sphincter/?action=open&token=" + token + "\n"
content += "- Tuer schliessen: https://labctl.ffa/sphincter/?action=close&token=" + token + "\n"
content += "- Status abfragen: https://labctl.ffa/sphincter/?action=state"
sender = '[email protected]'
try:
msg = MIMEText(content, 'plain')
msg['Subject'] = 'Dein OpenLab-Zugang'
msg['Date'] = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
msg['From'] = sender
conn = SMTP(server)
conn.set_debuglevel(False)
conn.login(username, password)
try:
conn.sendmail(sender, [address], msg.as_string())
finally:
conn.close()
except Exception, exc:
sys.exit( "mail failed; %s" % str(exc) )
示例8: sendMail
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def sendMail(RECIPIENT,SUBJECT,TEXT):
import sys
import os
import re
from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)
# from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
from email.MIMEText import MIMEText
SMTPserver = 'smtp.gmail.com'
sender = '[email protected]'
destination = [RECIPIENT]
USERNAME = "danbath"
PASSWORD = "4Fxahil3"
# typical values for text_subtype are plain, html, xml
text_subtype = 'plain'
try:
msg = MIMEText(TEXT, text_subtype)
msg['Subject']= SUBJECT
msg['From'] = sender # some SMTP servers will do this automatically, not all
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(USERNAME, PASSWORD)
try:
conn.sendmail(sender, destination, msg.as_string())
finally:
conn.close()
except Exception, exc:
sys.exit( "mail failed; %s" % str(exc) ) # give a error message
示例9: send_mail
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def send_mail(receivers, subject, content, attachment=None, filename=None):
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = config.FROM_EMAIL
msg['To'] = receivers
if config.DEV_ENV:
msg['To'] = config.TEST_TO_EMAIL
msg.preamble = 'Multipart message.\n'
part = MIMEText(content)
msg.attach(part)
if attachment:
part = MIMEApplication(open(attachment, "rb").read())
part.add_header('Content-Disposition', 'attachment', filename=filename)
msg.attach(part)
mailer = SMTP_SSL(config.SMTP_SERVER, config.SMTP_PORT)
# mailer.ehlo()
# mailer.starttls()
mailer.login(config.USERNAME, config.PASSWORD)
mailer.set_debuglevel(1)
mailer.sendmail(msg['From'], msg['To'].split(', '), msg.as_string())
mailer.close()
示例10: create_validator
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def create_validator(email):
key = list(string.ascii_uppercase + string.ascii_lowercase + string.digits)
random.shuffle(key)
key = ''.join(key[:25])
item = ValidationQueue(key=key, email=email)
item.save()
text = '''
Hello,
Please go to http://127.0.0.1:8000/b/confirm_account/''' + key + '''/ to validate your account.
Validation will take up to a minute. Please do not interrupt the process by closing the tab.
'''
message = MIMEText(text, 'plain')
message['Subject'] = 'Verify Account'
to_address = email
try:
conn = SMTP('smtp.gmail.com')
conn.set_debuglevel(True)
conn.login(from_address, password)
try:
conn.sendmail(from_address, to_address, message.as_string())
finally:
conn.close()
except Exception:
print("Failed to send email")
示例11: send_reminder_email
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def send_reminder_email(content, to, subject):
to = ['[email protected]', '[email protected]']
text_subtype = 'plain'
try:
msg = MIMEText(content.encode('utf-8'), text_subtype)
msg.set_charset('utf-8')
msg['Subject'] = subject
msg['From'] = smtp_conf['from']
msg['To'] = ','.join(to)
msg['Reply-To'] = smtp_conf['reply-to']
conn = SMTP(smtp_conf['server'], 465)
conn.set_debuglevel(False)
conn.login(smtp_conf['user'], smtp_conf['pass'])
try:
conn.sendmail(smtp_conf['from'], to, msg.as_string())
finally:
conn.close()
except Exception, exc:
sys.exit( "mail failed; %s" % str(exc) ) # give a error message
示例12: run
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def run(self):
if self.getSender() and \
self.getRecipient() and \
self.getSubject() and \
self.getContent():
try:
message = MIMEText(self.getContent(), self.getTextSubtype())
message['Subject'] = self.getSubject()
message['From'] = self.getSender()
connection = SMTP(self.getSmtpServer(), self.getPort())
connection.set_debuglevel(False)
connection.login(self.getUsername(), self.getPasswd())
try:
connection.sendmail(self.getSender(),
self.getRecipient(),
message.as_string())
finally:
connection.close()
except Exception, e:
print "Message to {0} failed: {1}".format(
self.getRecipient(), e)
示例13: sendEmail
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def sendEmail(text):
infoFp = open("Info.txt", "r")
sender = infoFp.readline().rstrip('\n')
password = infoFp.readline().rstrip('\n')
username = infoFp.readline().rstrip('\n')
SMTPserver = "smtp.gmail.com"
destination = sender
text_subtype = "plain"
if text == "":
print "You must supply valid text!"
return
else:
content = text
msg = MIMEText(content)
msg['Subject'] = "IRC ALERT"
msg['From'] = sender
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(username, password)
conn.sendmail(sender, destination, msg.as_string())
conn.close()
示例14: email_dir_zipped
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def email_dir_zipped(sender, recipient):
zf=tempfile.TemporaryFile(prefix='mail',suffix='.zip')
zipf=zipfile.ZipFile(zf,'w')
print "Zipping current dir: %s" %os.getcwd()
for file_name in os.listdir(os.getcwd()):
zipf.write(file_name)
zipf.close()
zf.seek(0)
print zf,zipf
print "Creating email message..."
print os.getcwd()[-1]+'.zip'
email_msg=MIMEMultipart()
email_msg['Subject']='File from path %s' %os.getcwd()
email_msg['To']=','.join(recipient)
email_msg['From']=sender
msg=MIMEBase('application','zip')
msg.set_payload(zf.read())
encoders.encode_base64(msg)
msg.add_header('Content-Disposition','attachment', file_name=os.getcwd()[-1]+'.zip')
email_msg.attach(msg)
email_msg=email_msg.as_string()
print "Sending email message..."
smtp=SMTP_SSL('smtp.163.com',465)
try:
smtp.login(sender, '51553963')
smtp.set_debuglevel(1)
smtp.sendmail(sender,recipient, email_msg)
except Exception, e:
print 'Error: %s' %str(e)
示例15: sendmail
# 需要导入模块: from smtplib import SMTP_SSL [as 别名]
# 或者: from smtplib.SMTP_SSL import set_debuglevel [as 别名]
def sendmail(to, app, attach0=False, attach1=False):
from smtplib import SMTP_SSL as SMTP
from email.MIMEText import MIMEText
destination = [to]
# read attach
contentattach = ''
if attach0 and not os.stat("%s" % attach0).st_size == 0:
fp = open(attach0,'rb')
contentattach += '------------------ Error begin\n\n'
contentattach += fp.read()
contentattach += '\n------------------ Error end'
fp.close()
if attach1 and not os.stat("%s" % attach1).st_size == 0:
fp = open(attach1,'rb')
contentattach += '\n\n------------------ Success begin\n\n'
contentattach += fp.read()
contentattach += '\n------------------ Success end'
fp.close()
msg = MIMEText(contentattach, 'plain')
msg['Subject'] = "Mr.Script %s" % app
msg['From'] = sender
try:
conn = SMTP(smtpserver)
conn.set_debuglevel(False)
conn.login(username, password)
conn.sendmail(sender, destination, msg.as_string())
conn.close()
except:
print ' *** Error trying send a mail. Check settings.'