def send_emails(self, sender, receivers, subject, content, cc=[], bcc=[], attachments=[]): """Send emails notes: No all email-service providers support. if using Gmail, enable "Access for less secure apps" for the sender's account, Examples: xxx.send_emails("James [email protected]", ['*****@*****.**', '*****@*****.**'], 'Subject: Hello', '<b>Hi! Here is the content of email</b>', ['*****@*****.**', '*****@*****.**'], ['*****@*****.**', '*****@*****.**'], ['C:/apache-maven-3.3.3-bin.zip']) :type sender: str|unicode :param sender: the nickname and email address of sender. Example:"James [email protected]" :type receivers: list :param receivers: receivers' emails address. Example:['*****@*****.**', '*****@*****.**'] :type subject: str|unicode :param subject: subject of email's header. Example:'Hello' :type content: str|unicode :param content: content of the email. Example:'<b>Hi!</b>' :type cc: list :param cc: CarbonCopy. Example:['*****@*****.**', '*****@*****.**'] :type bcc: list :param bcc: BlindCarbonCopy. Example:['*****@*****.**', '*****@*****.**'] :type attachments: list :param attachments: Example:['C:/Users/Administrator/Downloads/apache-maven-3.3.3-bin.zip'] :rtype boolean :return True if send emails successfully. False if fails to send. """ if not self.available: log.error(self.error_message) return False e = email(sender=sender, receivers=receivers, cc=cc, bcc=bcc, subject=subject, content=content, attachments=attachments) try: response = self.postman.send(e) if response.status_code == EMAIL_SMTP_STATUSCODE.SUCCESS: return True log.error("Send emails fail: " + response.message) return False except Exception as e: log.error(e) return False
def sendMail(message): p = postman(host='smtp.gmail.com', auth=(GMAILUSERNAME, GMAILPASSWORD)) r = p.send(email( content='<p><strong>New York Time Front Page</strong></p><p>%s</p>' % (message), subject='NY Times Front Page: %s' % (today), sender=SENDEREMAIL, receivers=[EMAILADDRESSES], )) if r.ok: print 'Sent!'
def send_email_notification(gmail_user, gmail_password, target_email, email_content, email_subject): user = '******'.format(gmail_user) p = postman(host='smtp.gmail.com', auth=(user, gmail_password)) r = p.send(email( content=email_content, subject=email_subject, sender='{0} <{0}>'.format(user), receivers=[target_email], )) assert r.ok
def send_emails(self): content = self.csv_content[1:] for row in content: envelope = email(sender=self.sender, receivers=[row[0]], subject=self.subject, content=self.construct_msg(row)) # Spawn a thread for each email delivery thr = Thread(target=self.send_async_email, args=[envelope]) thr.start() return thr
def send_emails(self): content = self.csv_content[1:] for row in content: envelope = email( sender=self.sender, receivers=[row[0]], subject=self.subject, content=self.construct_msg(row)) # Spawn a thread for each email delivery thr = Thread(target=self.send_async_email, args=[envelope]) thr.start() return thr
def send_email(config, user_email, subject, content): envelope = email(sender=SENDER, receivers=[user_email], subject=subject, content=content) postman = Postman(host=config['host'], port=int(config['port']), middlewares=[TLS(force=True), Auth(username=config['username'], password=config['password'])]) postman.send(envelope)
def send_mail(data, cancel=False): """Send an email""" body = "Le train de %s (%s - %s) a été %s." % ( data['date'], translate_station( data['from_gare']), translate_station(data['to_gare']), u'supprimé' if not cancel else u'remis en service') the_email = email(subject='%sSuppression Transilien' % (u'[ANNULATION] ' if cancel else ''), content=body, sender=settings.MAIL_DEFAULT_SENDER, receivers=settings.MAIL_RECIPIENTS) if not settings.TESTING: smtp = postman(host=settings.MAIL_SERVER, port=settings.MAIL_PORT) smtp.send(the_email)
def send_email(config, user_email, subject, content): envelope = email(sender=SENDER, receivers=[user_email], subject=subject, content=content) postman = Postman( host=config["mail.host"], port=int(config["mail.port"]), middlewares=[TLS(force=True), Auth(username=config["mail.username"], password=config["mail.password"])], ) try: response = postman.send(envelope) if response.ok: logger.info("Successfully send email to %s" % user_email) else: logger.error("Failed to send email to %s" % user_email) except Exception, e: logger.error("Exception occured when send email to %s" % e)
def send_email_notification(self, email_subject, email_content, attachment): with self.lock: for recipient in self.recipients: p = postman(host='smtp.gmail.com', auth=(self.sender_email, self.gmail_password)) r = p.send( email(content=email_content, subject=email_subject, sender='{0} <{0}>'.format(self.sender_email), receivers=[recipient], attachments=[attachment])) logger.info(f'Email subject is {email_subject}.') logger.info(f'Email content is {email_content}.') logger.info(f'Attachment located at {attachment}.') logger.info(f'Notification sent from {self.sender_email}.') logger.info(f'Notification sent to {recipient}.') assert r.ok
def push(self, receivers, attachments, *args, **kwargs): if not receivers: receivers = pushConf.receiver if not receivers: raise KindlePushError, "receiver empty" receivers_list = receivers.split(',') if not attachments: raise KindlePushError, "attachments empty" if isinstance(attachments, str): attachments = attachments.split(',') smtp = postman(host=pushConf.smtpHost, auth=(pushConf.username, pushConf.password)) smtp.send(email( sender=pushConf.sender, receivers=receivers_list, attachments=attachments ))
def send_email_notification(self, email_subject, email_content, attachment=None): if self.use_module: with self.lock: if attachment is not None: attachment = [attachment] else: attachment = () for recipient in self.recipients: p = postman(host='smtp.gmail.com', auth=(self.gmail_user, self.gmail_password)) r = p.send(email(content=email_content, subject=email_subject, sender='{0} <{0}>'.format(self.gmail_user), receivers=[recipient], attachments=attachment)) logger.info(f'Email subject is {email_subject}.') logger.info(f'Email content is {email_content}.') logger.info(f'Attachment located at {attachment}.') logger.info(f'Notification sent from {self.gmail_user} to {recipient}.') assert r.ok
def send(self, content, to, subject='提示信息'): flag, _ = self._check(to) if not flag: print('邮箱格式不合法') assert 1 == 2 content = content.replace('\n', '<br>') content = '<p>' + content + '<p>' r = self.p.send(email( content=content, subject=subject, sender='{} <{}>'.format(self.name, self.address), receivers=[to], )) if not r.ok: print('发送失败') self.ok = False else: self.ok = True
def send_email(config, user_email, subject, content): envelope = email( sender=SENDER, receivers=[user_email], subject=subject, content=content ) postman = Postman(host=config['mail.host'], port=int(config['mail.port']), middlewares=[TLS(force=True), Auth(username=config['mail.username'], password=config['mail.password'])]) try: response = postman.send(envelope) if response.ok: logger.info("Successfully send email to %s" % user_email) else: logger.error("Failed to send email to %s" % user_email) except Exception, e: logger.error("Exception occured when send email to %s" % e)
def send_email(success, user_info): content = 'Your CUNYFirst Automated Enrollment for the ' + user_info[ 'term'] + ' at ' + user_info['college'] + ' has completed ' if success: status = 'Success' content = content + 'successfully.' else: status = 'Failure' content = content + 'with one or more errors on 2 attempts. ' \ 'Please check CUNYFirst to fix your errors and finish your enrollment.' email_config = config['EMAIL'] p = postman(host=email_config['email_host'], port=email_config['port'], auth=(email_config['email'], email_config['email_pass']), force_tls=True) e = email(sender='Nathanael Gutierrez <*****@*****.**>', subject='CUNYFirst Enrollment Automator: ' + status, content=content, encoding='utf8', receivers=[user_info['email']]) p.send(e)
def email(): postman = Postman( host='SOLLOES-VM02.SOLLOBRASIL.NET', port=587, middlewares=[ TLS(force=True), Auth(username='******', password='******') ], ) envelope = email( sender='sender <*****@*****.**>', receivers=['*****@*****.**'], subject='Manutenção/Suporte', content='', ) response = postman.send(envelope) print(response.message) print(response.status_code) if response.ok: print("OK! :)")
def send_alert(alert_video_package): print alert_video_package title = alert_video_package["name"] bc_id = alert_video_package["videoID"] bc_desc = alert_video_package["description"] video_url = alert_video_package["url"] # this is an "envelope" that is an email ''' envelope = Envelope( headers={ 'Sender': 'sender <*****@*****.**>', 'To': '*****@*****.**', 'Subject': 'Hello World!', }, enclosure=[ PlainText('Hi!'), ] ) ''' # this is email with an HTML enclosure, not plaintext like above envelope = email( sender='sender <*****@*****.**>', receivers=['*****@*****.**', '*****@*****.**'], subject='Rio Olympics video alert', content="""\ <html> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> </head> <body> <table class="table table-inverse"> <thead> <tr> <th>The following video is available in Gannett - USA TODAY Brightcove account:</th> </tr> </thead> <tbody> <tr> <th scope="row">Title:</th> <td>%s</td> </tr> <tr> <th scope="row">Video ID:</th> <td>%s</td> </tr> <tr> <th scope="row">Description:</th> <td>%s</td> </tr> <tr> <th scope="row">Source File URL:</th> <td>%s</td> </tr> </tbody> </table> </body> </html> """ % (title, bc_id, bc_desc, video_url) ) # this is a "postman" configured for Gmail ''' postman = Postman( host='mail.google.com', port=587, middlewares=[ TLS(force=True), Auth(username='******', password='******') ], ) ''' # https://support.google.com/a/answer/176600?hl=en # using postman function, simpler version of above function postman = postman_( #host='mail.google.com', host='smtp.gmail.com', port=587, force_tls=True, auth=('*****@*****.**', password='******'), )
from mailthon.postman import Postman from mailthon.middleware import TLS, Auth from mailthon import email while (True): postman = Postman( host='smtp-mail.outlook.com', port=587, middlewares=[ TLS(force=True), Auth(username='******', password='') ], ) envelope = email( sender='sender <*****@*****.**>', receivers=['*****@*****.**'], subject='Manutenção/Suporte', content='Hi', ) response = postman.send(envelope) print(response.message) print(response.status_code) if response.ok: print("OK! :)")
# -*- coding:utf-8 -*- from mailthon import postman, email p = postman(host='smtp.126.com', port=25, auth=('*****@*****.**', '授权码')) r = p.send(email( # 内容 content=u'<p>Hello 世界</p>', # 标题 subject='Hello world', # 发件人 sender='John <*****@*****.**>', # 收件人列表 receivers=['*****@*****.**'], # 附件 attachments=[ '/xxx/x.pdf, '/xxx/x.png' ] )) assert r.ok