本文整理汇总了Python中smtplib.SMTP_SSL类的典型用法代码示例。如果您正苦于以下问题:Python SMTP_SSL类的具体用法?Python SMTP_SSL怎么用?Python SMTP_SSL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SMTP_SSL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendmail
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()
示例2: _sendMail
def _sendMail(self, message, request):
if message['subject']=='QUESTION':
txt='\r\n'+'NAME: '+message['name']+'\r\n'+'\r\n'+'EMAIL: '+message['email']+'\r\n'+'\r\n'+'QUESTION: '+message['question']+'\r\n'
elif message['subject']=='ORDER':
txt='\r\n'+'NAME: '+message['name']+'\r\n'+'\r\n'+'EMAIL: '+message['email']+'\r\n'+'\r\n'+ \
'ENTIRE LANGUAGE: '+message['entire_language']+'\r\n'+'CAPTION LANGUAGE: '+message['caption_language']+ \
'\r\n'+'VIDEO DURATION: '+message['duration']+'\r\n'+'TIME LIMIT: '+message['time_limit']+ \
'\r\n'+'VOICE OVER: '+message['voice_over']+'\r\n'+'DISCOUNT: '+message['discount']+'\r\n'+ \
'VIDEO LINK:'+message['videolink']+'\r\n'+'SPECIAL: '+message['special']
elif message['subject']=='CUSTOM ORDER':
txt='\r\n'+'NAME: '+message['name']+'\r\n'+'\r\n'+'EMAIL: '+message['email']+'\r\n'+'\r\n'+'COMPANY: '+ \
message['company']+'\r\n'+'REQUIREMENTS: '+message['requirements']
elif message['subject']=='FREE MINUTE':
txt='\r\n'+'EMAIL: '+message['email']+'\r\n'
msg=MIMEText(txt)
msg['Subject']=message['subject']
msg['From']=message['email']
msg['To']=self.addr
smtp = SMTP_SSL(self.hst)
smtp.login(self.addr,self.psswd)
smtp.sendmail(self.addr,self.addr,msg.as_string())
request.write('Your mail sent.')
request.finish()
示例3: __init__
def __init__(self, **kw):
args = {}
for k in ('host', 'port', 'local_hostname', 'keyfile', 'certfile', 'timeout'):
if k in kw:
args[k] = kw[k]
SMTP_SSL.__init__(self, **args)
SMTPClientWithResponse.__init__(self, **kw)
示例4: render_POST
def render_POST(self, request):
message = ast.literal_eval(request.content.read())
if message['subject']=='QUESTION':
txt='\r\n'+'NAME: '+message['name']+'\r\n'+'\r\n'+'EMAIL: '+message['email']+'\r\n'+'\r\n'+'QUESTION: '+message['question']+'\r\n'
elif message['subject']=='ORDER':
txt='\r\n'+'NAME: '+message['name']+'\r\n'+'\r\n'+'EMAIL: '+message['email']+'\r\n'+'\r\n'+ \
'ENTIRE LANGUAGE: '+message['entire_language']+'\r\n'+'CAPTION LANGUAGE: '+message['caption_language']+ \
'\r\n'+'VIDEO DURATION: '+message['duration']+'\r\n'+'TIME LIMIT: '+message['time_limit']+ \
'\r\n'+'VOICE OVER: '+message['voice_over']+'\r\n'+'DISCOUNT: '+message['discount']+'\r\n'+ \
'VIDEO LINK:'+message['videolink']+'\r\n'+'SPECIAL: '+message['special']
elif message['subject']=='CUSTOM ORDER':
txt='\r\n'+'NAME: '+message['name']+'\r\n'+'\r\n'+'EMAIL: '+message['email']+'\r\n'+'\r\n'+'COMPANY: '+ \
message['company']+'\r\n'+'REQUIREMENTS: '+message['requirements']
elif message['subject']=='FREE MINUTE':
txt='\r\n'+'EMAIL: '+message['email']+'\r\n'
msg=MIMEText(txt)
msg['Subject']=message['subject']
msg['From']=message['email']
msg['To']=self.addr
request.setHeader("Access-Control-Allow-Origin", "*")
smtp = SMTP_SSL(self.hst)
smtp.login(self.addr,self.psswd)
smtp.sendmail(self.addr,self.addr,msg.as_string())
return 'Your mail sent.'
示例5: send
def send(message):
global datas
global numbers
s = SMTP_SSL('smtp.gmail.com', 465, timeout=10)
s.login(datas[0],datas[1])
for n in numbers:
s.sendmail(datas[0], numbers[n], str(message))
s.quit
示例6: send_mail
def send_mail(message):
try:
smtpObj = SMTP_SSL(mail_host,465)
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print "邮件发送成功"
except smtplib.SMTPException:
print "无法发送邮件"
示例7: _open
def _open(self):
if self.conn:
return
conn = SMTP_SSL(self.config_d['smtp_host'],
self.config_d['smtp_port'])
conn.ehlo()
conn.login(self.config_d['smtp_user'],
self.config_d['smtp_password'])
self.conn = conn
示例8: render_POST
def render_POST(self, request):
print request.content.read()
addr='[email protected]'
msg=MIMEMultipart()
msg['From']=msg['To']=addr
request.setHeader("Access-Control-Allow-Origin", "*")
smtp = SMTP_SSL('smtp.yandex.ru:465')
smtp.login('[email protected]','48919o6')
smtp.sendmail(addr,addr,msg.as_string())
return 'Your mail sent.'
示例9: sendMessage
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.")
示例10: landing_customer_contacts
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()
示例11: sendmail
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()
示例12: sendMail
def sendMail(emailTo, subject, msgText, fileAddr):
filepath = fileAddr
basename = os.path.basename(filepath)
address = "[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)
part3 = MIMEBase('application', "octet-stream")
part3.set_payload(open(os.getcwd() + '/plan_rabot_po_saitu_na_god.xlsx',"rb").read() )
Encoders.encode_base64(part3)
part3.add_header('Content-Disposition', 'attachment; filename="plan_rabot_po_saitu_na_god.xlsx"')
part2 = MIMEText(msgText, 'plain')
# Compose message
msg = MIMEMultipart()
msg['From'] = 'Михаил Юрьевич Бубновский <[email protected]>'
msg['To'] = emailTo
msg['Subject'] = subject
msg.attach(part2)
msg.attach(part)
msg.attach(part3)
# Send mail
smtp = SMTP_SSL()
smtp.connect('smtp.yandex.ru')
smtp.login(address, 'biksileev')
smtp.sendmail(address, emailTo, msg.as_string())
smtp.quit()
示例13: sent
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()
示例14: _use_smtp
def _use_smtp(self, subject, body, path):
# if self.smtp_server is not provided than don't try to send email via smtp service
logging.debug('SMTP Mail delivery: Started')
# change to smtp based mail delivery
# depending on encrypted mail delivery, we need to import the right lib
if self.smtp_encryption:
# lib with ssl encryption
logging.debug('SMTP Mail delivery: Import SSL SMTP Lib')
from smtplib import SMTP_SSL as SMTP
else:
# lib without encryption (SMTP-port 21)
logging.debug('SMTP Mail delivery: Import standard SMTP Lib (no SSL encryption)')
from smtplib import SMTP
conn = False
try:
outer = MIMEMultipart()
outer['Subject'] = subject # put subject to mail
outer['From'] = 'Your PicoChess computer <{}>'.format(self.smtp_from)
outer['To'] = self.email
outer.attach(MIMEText(body, 'plain')) # pack the pgn to Email body
ctype, encoding = mimetypes.guess_type(path)
if ctype is None or encoding is not None:
ctype = 'application/octet-stream'
maintype, subtype = ctype.split('/', 1)
if maintype == 'text':
with open(path) as fpath:
msg = MIMEText(fpath.read(), _subtype=subtype)
elif maintype == 'image':
with open(path, 'rb') as fpath:
msg = MIMEImage(fpath.read(), _subtype=subtype)
elif maintype == 'audio':
with open(path, 'rb') as fpath:
msg = MIMEAudio(fpath.read(), _subtype=subtype)
else:
with open(path, 'rb') as fpath:
msg = MIMEBase(maintype, subtype)
msg.set_payload(fpath.read())
encoders.encode_base64(msg)
msg.add_header('Content-Disposition', 'attachment', filename=os.path.basename(path))
outer.attach(msg)
logging.debug('SMTP Mail delivery: trying to connect to ' + self.smtp_server)
conn = SMTP(self.smtp_server) # contact smtp server
conn.set_debuglevel(False) # no debug info from smtp lib
if self.smtp_user is not None and self.smtp_pass is not None:
logging.debug('SMTP Mail delivery: trying to log to SMTP Server')
conn.login(self.smtp_user, self.smtp_pass) # login at smtp server
logging.debug('SMTP Mail delivery: trying to send email')
conn.sendmail(self.smtp_from, self.email, outer.as_string())
# @todo should check the result from sendmail
logging.debug('SMTP Mail delivery: successfuly delivered message to SMTP server')
except Exception as smtp_exc:
logging.error('SMTP Mail delivery: Failed')
logging.error('SMTP Mail delivery: ' + str(smtp_exc))
finally:
if conn:
conn.close()
logging.debug('SMTP Mail delivery: Ended')
示例15: send_token
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) )