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
示例#2
0
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!'
示例#3
0
文件: mail.py 项目: Asdil/Asdil
 def __init__(self, host, address, pwd):
     """
     :param host:     POP3/IMAP/SMTP/Exchange服务
     :param address:  邮箱地址
     :param pwd:      授权码wtqngyeotfiybhii
     """
     flag, name = self._check(address)
     if not flag:
         print('邮箱格式不合法')
         assert 1 == 2
     self.p = postman(host=host, auth=(address, pwd))
     self.address = address
     self.name = name
     self.ok = None
示例#4
0
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)
示例#5
0
 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
示例#6
0
	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
		))
示例#7
0
 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_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)
示例#9
0
        mailthon.headers.subject("3-Headers.py"),
        mailthon.headers.date(),
        mailthon.headers.message_id(),
        ]
# mailthon comes with a Headers class that magically encodes everything in
# Unicode that we can use. It operates like dict (and inherits from dict too)
headers_obj = mailthon.headers.Headers(headers)
# rfc 2822 says that Sender should be sufficient if From doesn't exist, but
# I've noticed that this is often not the case
headers_obj['From'] = email

# note that if you're opening a file to read it as a binary, you'd probably be
# better off using the Attachment enclosure. This is just an example though.
with open("sample.pdf", "rb") as pdf_attachment_file:
    pdf_attachment_binary = pdf_attachment_file.read()

# as mentioned in 2-Enclosure.py, Binary enclosures need to have their headers
# manually filled. These can be done using mailthon.headers.content_disposition
pdf_attachment = mailthon.enclosure.Binary(
        content=pdf_attachment_binary,
        mimetype="application/pdf",
        headers=[
            mailthon.headers.content_disposition("attachment", "sample.pdf"),
            ],
        )

enclosures = [mailthon.enclosure.PlainText("3-Headers.py"), pdf_attachment]

postman = mailthon.postman(smtp, auth=auth)
postman.send(mailthon.envelope.Envelope(headers_obj, enclosures))
示例#10
0
文件: demon.py 项目: Asdil/send_mail
# -*- 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