Exemplo n.º 1
0
 def test_attachment_unicode_filename(self):
     msg = Message(fromaddr='*****@*****.**', to='*****@*****.**')
     # Chinese filename :)
     msg.attach_attachment(u'我的测试文档.txt', 'text/plain',
                           'this is test')
     self.assert_in('filename*="utf-8\'\'%E6%88%91%E7%9A%84%E6%B5%8B%E8%AF'
                    '%95%E6%96%87%E6%A1%A3.txt"', str(msg))
Exemplo n.º 2
0
 def test_to(self):
     msg = Message(fromaddr='*****@*****.**', to='*****@*****.**')
     self.assert_equal(msg.to, set(['*****@*****.**']))
     self.assert_in('*****@*****.**', str(msg))
     msg = Message(to=['*****@*****.**', '*****@*****.**'])
     self.assert_equal(msg.to, set(['*****@*****.**',
                                    '*****@*****.**']))
Exemplo n.º 3
0
 def test_plain_text_with_attachments(self):
     msg = Message(fromaddr='*****@*****.**',
                   to='*****@*****.**',
                   subject='hello',
                   body='hello world')
     msg.attach_attachment(content_type='text/plain', data=b'this is test')
     self.assert_in('Content-Type: multipart/mixed', str(msg))
Exemplo n.º 4
0
 def test_attachment_unicode_filename(self):
     msg = Message(fromaddr='*****@*****.**', to='*****@*****.**')
     # Chinese filename :)
     msg.attach_attachment(u'我的测试文档.txt', 'text/plain', 'this is test')
     self.assert_in(
         'UTF8\'\'%E6%88%91%E7%9A%84%E6%B5%8B%E8%AF'
         '%95%E6%96%87%E6%A1%A3.txt', str(msg))
Exemplo n.º 5
0
def send_alarm_mail(ip_target, ping_loss):
    curl_dir = os.path.split(os.path.realpath(__file__))[0]
    db_file = os.path.join(curl_dir, "p_a_t.db")
    con = sqlite3.connect(db_file)
    cur = con.cursor()
    sql_select = "select * from smtp_server where active=1"
    cur.execute(sql_select)
    smtp_info = cur.fetchone()

    if smtp_info:
        mail = Mail(smtp_info[1],
                    port=smtp_info[2],
                    username=smtp_info[3],
                    password=smtp_info[4],
                    use_ssl=True,
                    fromaddr=smtp_info[3])

        msg = Message("[Alarm]{} loss {}%".format(ip_target, ping_loss))
        receivers = []
        for i in smtp_info[6].split(","):
            receivers.append(i)
        msg.to = receivers
        msg.body = ""
        with open("{}.txt".format(ip_target)) as f:
            for i in f.readlines():
                msg.body += i
        mail.send(msg)
        print("Alarm mail send successful.Receivers are :{}".format(receivers))
    else:
        print("There's no active SMTP server,can't send alarm mail.")
Exemplo n.º 6
0
def send_mail(srv_name):
    '''发送邮件'''
    data = request.get_json()
    if srv_name not in config:
        logging.warning('!!!'+str(datetime.datetime.now())+'InvalidService!!!')
        return jsonify({"status":1, "msg":"InvalidService"})
    else:
        srv_config = config[srv_name]
    if not verify_key(srv_name, data['key']):
        logging.warning('!!!'+str(datetime.datetime.now())+'InvalidKey!!!')
        return jsonify({"status":1, "msg":"InvalidKey"})

    mail_msg = Message(data['mail_title'], fromaddr=srv_config['mail_from'], to=data['mail_to'])
    mail_msg.html = data['mail_html']
    mail = Mail(
        srv_config['smtp'],
        port=srv_config['port'],
        username=srv_config['mail_from'],
        password=srv_config['smtppass'],
        use_tls=srv_config['tls'],
        use_ssl=srv_config['ssl'],
        debug_level=None
        )
    try:
        logging.info('--------'+str(datetime.datetime.now())+'--------------')
        logging.info(data['mail_title'])
        logging.info(data['mail_to'])
        logging.info(data['mail_html'])
        logging.info('=======================================================')
        mail.send(mail_msg)
        return jsonify({"status":0, "msg":"Success"})
    except Exception as e:
        logging.warning('!!!'+str(datetime.datetime.now())+'!!!')
        logging.warning(str(e))
        return jsonify({"status":2, "msg":str(e)})
Exemplo n.º 7
0
 def test_fromaddr(self):
     msg = Message(fromaddr='*****@*****.**', to='*****@*****.**')
     self.assert_equal(msg.fromaddr, '*****@*****.**')
     self.assert_in('*****@*****.**', str(msg))
     msg = Message()
     msg.fromaddr = ('From', '*****@*****.**')
     self.assert_equal(msg.fromaddr, u'From <*****@*****.**>')
Exemplo n.º 8
0
 def test_fromaddr(self):
     msg = Message(fromaddr='*****@*****.**', to='*****@*****.**')
     self.assert_equal(msg.fromaddr, '*****@*****.**')
     self.assert_in('*****@*****.**', str(msg))
     msg = Message()
     msg.fromaddr = ('From', '*****@*****.**')
     self.assert_in('<*****@*****.**>', str(msg))
Exemplo n.º 9
0
 def test_mail_and_rcpt_options(self):
     msg = Message()
     self.assert_equal(msg.mail_options, [])
     self.assert_equal(msg.rcpt_options, [])
     msg = Message(mail_options=['BODY=8BITMIME'])
     self.assert_equal(msg.mail_options, ['BODY=8BITMIME'])
     msg = Message(rcpt_options=['NOTIFY=OK'])
     self.assert_equal(msg.rcpt_options, ['NOTIFY=OK'])
Exemplo n.º 10
0
 def test_attach(self):
     msg = Message()
     att = Attachment()
     atts = [Attachment() for i in range(3)]
     msg.attach(att)
     self.assert_equal(msg.attachments, [att])
     msg.attach(atts)
     self.assert_equal(msg.attachments, [att] + atts)
Exemplo n.º 11
0
def send(text, subject=None, toAdd=None, cc=None, log_file=None):
    mail_info = config.config_dic['mail_info']
    sslPort = 465
    server = mail_info.get('server')
    user = mail_info.get('user')
    passwd = mail_info.get('password')

    if not (server and user and passwd):
        print('Invalid login info, exit!')
        return

    mail = Mail(server,
                port=sslPort,
                username=user,
                password=passwd,
                use_tls=False,
                use_ssl=True,
                debug_level=None)
    msg = Message(subject)
    msg.fromaddr = (user, user)
    msg.to = toAdd
    if cc:
        msg.cc = cc

    if log_file:
        zip_path = '/tmp/build.log.zip'
        zip_file(log_file, zip_path)
        with open(zip_path, encoding='ISO-8859-1') as f:
            attachment = Attachment("build.log.zip",
                                    "application/octet-stream", f.read())
            msg.attach(attachment)

    msg.body = text
    msg.charset = "utf-8"
    mail.send(msg)
Exemplo n.º 12
0
def send(text, subject=None, cc=None, toAdd=None, log_file=None):
    mail_info = config.config_dic['mail_info']
    sslPort = 465
    server = mail_info.get('server')
    user = mail_info.get('user')
    passwd = mail_info.get('password')

    if not (server and user and passwd):
        print('Invalid login info, exit!')
        return

    mail = Mail(server,
                port=sslPort,
                username=user,
                password=passwd,
                use_tls=False,
                use_ssl=True,
                debug_level=None)
    msg = Message(subject)
    msg.fromaddr = (user, user)
    msg.to = toAdd
    if cc:
        msg.cc = cc

    if log_file:
        with open(log_file) as f:
            attachment = Attachment("build.log", "text/plain", f.read())
            msg.attach(attachment)

    msg.body = text
    msg.charset = "utf-8"
    mail.send(msg)
Exemplo n.º 13
0
 def __send_email_to(self, user, bangumi_map):
     info = {
         'username': user.name,
         'root_path': self.root_path,
         'sys': False
     }
     bangumi_list = self.__bangumi_map_to_list(bangumi_map)
     msg = Message('Download Status Alert', fromaddr=('Alert System', self.mail_config['mail_default_sender']))
     msg.to = user.email
     msg.html = self.mail_template.render(info=info, bangumi_list=bangumi_list)
     return msg
Exemplo n.º 14
0
def sendMail(to, subject, msgContext):
    pLog("Send Server Mail")
    config = ConfigParser.RawConfigParser()
    config.read('defaults.cfg')
    msg = Message(subject, fromaddr=config.get('SendAbuse', 'from'), to=to)
    if(to!=config.get('SendAbuse', 'from')):
        msg.bcc = config.get('SendAbuse', 'from')
    msg.body = msgContext
    msg.date = time.time()
    msg.charset = "utf-8"
    mail = Mail(config.get('SendAbuse', 'server'), port=config.get('SendAbuse', 'port'), username=config.get('SendAbuse', 'user'), password=config.get('SendAbuse', 'pass'),use_tls=False, use_ssl=False, debug_level=None)
    mail.send(msg)
Exemplo n.º 15
0
 def test_to_addrs(self):
     msg = Message(to='*****@*****.**')
     self.assert_equal(msg.to_addrs, set(['*****@*****.**']))
     msg = Message(to='*****@*****.**',
                   cc='*****@*****.**',
                   bcc=['*****@*****.**', '*****@*****.**'])
     expected_to_addrs = set([
         '*****@*****.**', '*****@*****.**', '*****@*****.**',
         '*****@*****.**'
     ])
     self.assert_equal(msg.to_addrs, expected_to_addrs)
     msg = Message(to='*****@*****.**', cc='*****@*****.**')
     self.assert_equal(msg.to_addrs, set(['*****@*****.**']))
Exemplo n.º 16
0
def send_jobs(jobs):
    "Send an email notifying of current jobs"
    msg = Message(
        config['email']['subject'].format(n=len(jobs)),
        to=config['email_address'],
    )

    msg.body = "Found {n} potential jobs:\n\n"
    for idx, job in enumerate(jobs):
        idx += 1
        msg.body += "{}. {}\n\n\n".format(idx, job.to_string())

    MAIL.send(msg)
Exemplo n.º 17
0
 def test_validate(self):
     msg = Message(fromaddr='*****@*****.**')
     self.assert_raises(SenderError, msg.validate)
     msg = Message(to='*****@*****.**')
     self.assert_raises(SenderError, msg.validate)
     msg = Message(subject='subject\r',
                   fromaddr='*****@*****.**',
                   to='*****@*****.**')
     self.assert_raises(SenderError, msg.validate)
     msg = Message(subject='subject\n',
                   fromaddr='*****@*****.**',
                   to='*****@*****.**')
     self.assert_raises(SenderError, msg.validate)
Exemplo n.º 18
0
 def __send_email_to(self, user, bangumi_map):
     info = {
         'username': user.name,
         'root_path': self.root_path,
         'sys': False
     }
     bangumi_list = self.__bangumi_map_to_list(bangumi_map)
     msg = Message('Download Status Alert',
                   fromaddr=('Alert System',
                             self.mail_config['mail_default_sender']))
     msg.to = user.email
     msg.html = self.mail_template.render(info=info,
                                          bangumi_list=bangumi_list)
     return msg
Exemplo n.º 19
0
 def __send_email_to_all(self, admin_list, bangumi_map):
     msg_list = []
     for user in admin_list:
         info = {
             'username': user.name,
             'root_path': self.root_path,
             'sys': True
         }
         bangumi_list = self.__bangumi_map_to_list(bangumi_map)
         msg = Message('Download Status Alert', fromaddr=('Alert System', self.mail_config['mail_default_sender']))
         msg.to = user.email
         msg.html = self.mail_template.render(info=info, bangumi_list=bangumi_list)
         msg_list.append(msg)
     return msg_list
Exemplo n.º 20
0
 def test_html(self):
     html_text = '<b>Hello</b><br/>It works.'
     msg = Message(fromaddr='*****@*****.**',
                   to='*****@*****.**',
                   html=html_text)
     self.assert_equal(msg.html, html_text)
     self.assert_in('Content-Type: multipart/alternative', str(msg))
Exemplo n.º 21
0
 def test_plain_text(self):
     plain_text = 'Hello!\nIt works.'
     msg = Message(fromaddr='*****@*****.**',
                   to='*****@*****.**',
                   body=plain_text)
     self.assert_equal(msg.body, plain_text)
     self.assert_in('Content-Type: text/plain', str(msg))
Exemplo n.º 22
0
 def test_process_address(self):
     msg = Message(fromaddr=('From\r\n', 'from\r\[email protected]'),
                   to='to\[email protected]',
                   reply_to='reply-to\[email protected]')
     self.assert_in('<*****@*****.**>', str(msg))
     self.assert_in('*****@*****.**', str(msg))
     self.assert_in('*****@*****.**', str(msg))
Exemplo n.º 23
0
 def __send_email_to_all(self, admin_list, bangumi_map):
     msg_list = []
     for user in admin_list:
         info = {
             'username': user.name,
             'root_path': self.root_path,
             'sys': True
         }
         bangumi_list = self.__bangumi_map_to_list(bangumi_map)
         msg = Message('Download Status Alert',
                       fromaddr=('Alert System',
                                 self.mail_config['mail_default_sender']))
         msg.to = user.email
         msg.html = self.mail_template.render(info=info,
                                              bangumi_list=bangumi_list)
         msg_list.append(msg)
     return msg_list
Exemplo n.º 24
0
def run(arguments):
    if arguments['--config'] or (not os.path.isfile(CONF)):
        conf()
    with open(CONF, 'rb') as f:
        smtp = json.loads(f.read())
    mail = Mail(host=smtp['server'],
                username=smtp['user'],
                password=smtp['password'],
                port=int(smtp['port']),
                fromaddr=smtp['from'])
    msg = Message(arguments['--subject'],
                  fromaddr=smtp['from'],
                  body=arguments['--message'])
    to = arguments['--to']
    if to:
        msg.to = to.split(';')
    cc = arguments['--cc']
    if cc:
        msg.cc = cc.split(';')
    bcc = arguments['--bcc']
    if bcc:
        msg.bcc = bcc.split(';')
    atta = arguments['--attach']
    if atta:
        msg.attach(atta.split(';'))
    mail.send(msg)
Exemplo n.º 25
0
 def test_attach(self):
     msg = Message()
     att = Attachment()
     atts = [Attachment() for i in range(3)]
     msg.attach(att)
     self.assert_equal(msg.attachments, [att])
     msg.attach(atts)
     self.assert_equal(msg.attachments, [att] + atts)
Exemplo n.º 26
0
def send_message(subject, to, body):
	mail = Mail(MAIL_SMTP_ADDRESS, port=MAIL_PORT,
	username=FROM_EMAIL, password=MAIL_PASSWORD,
			use_tls=False, use_ssl=False, debug_level=None)

	msg = Message()
	msg = Message(subject)
	msg.fromaddr = (FROM_NAME, FROM_EMAIL)
	msg.to = to

	msg.bcc = [DEV_EMAIL]
	msg.html = body

	mail.send(msg)
	return True
Exemplo n.º 27
0
def send(text, subject, toAdd, cc=None, attachments=None):
    """邮件发送方法
    
    Arguments:
        text {str} -- 邮件内容,可以为字符串或者 HTML 字符串
        subject {str} -- 邮件标题
        toAdd {list} -- 收件人列表 
    
    Keyword Arguments:
        cc {list} -- 抄送人列表 (default: {None}) 
        attachments {list} -- 附件列表,示例:[{'path': '/path/to/file', 'file_name': '附件文件名'}] (default: {None})
    """
    
    assert subject is not None
    assert toAdd is not None
    sslPort = os.getenv('MAIL_SERVER_PORT')
    server = os.getenv('MAIL_SMTP_SERVER')
    user = os.getenv('MAIL_USER')
    passwd = os.getenv('MAIL_PASSWORD')

    assert server is not None
    assert user is not None
    assert passwd is not None
    if not sslPort:
        sslPort = 465

    mail = Mail(server, port=sslPort, username=user, password=passwd,
                use_tls=False, use_ssl=True, debug_level=None)
    msg = Message(subject)
    msg.fromaddr = (user, user)
    msg.to = toAdd
    if cc:
        msg.cc = cc 
    if attachments:
        for att in attachments:
            with open(att['path'], 'rb') as f:
                mail_attachment = Attachment(att['file_name'], "application/octet-stream", f.read())
                msg.attach(mail_attachment)
    
    msg.html = text
    msg.charset = "utf-8"
    mail.send(msg)
Exemplo n.º 28
0
    def createMail(self, name, comment, email):
        msg = Message()
        sub = 'Comment From dh314Blog '
        msg.fromaddr = ('Đường Hạo', '*****@*****.**')
        msg.subject = sub
        contentE = 'Bạn nhận được một comments từ dh314Blog \n Từ: ' + str(
            name) + '\nEmail: ' + str(email) + '\nNội dung: ' + str(comment)
        msg.body = contentE
        msg.to = '*****@*****.**'

        return msg
Exemplo n.º 29
0
def send_mail(subject, to, content, cc=None, type='plain', system='自动'):
    if cc is None:
        cc = []

    html, body = None, None
    if type == 'html':
        html = content
    else:
        body = content

    subject = subject.replace('\n', ' ')
    subject = '[{}]{}'.format(system, subject)
    mail = Mail(host=host, port=25, username=sender, password=password)
    msg = Message(subject=subject,
                  to=to,
                  cc=cc,
                  html=html,
                  body=body,
                  fromaddr=sender)
    mail.send(msg)
Exemplo n.º 30
0
def sendMail(to, subject, msgContext):
    pLog("Send Server Mail")
    config = ConfigParser.RawConfigParser()
    config.read('defaults.cfg')
    msg = Message(subject, fromaddr=config.get('SendAbuse', 'from'), to=to)
    if (to != config.get('SendAbuse', 'from')):
        msg.bcc = config.get('SendAbuse', 'from')
    msg.body = msgContext
    msg.date = time.time()
    msg.charset = "utf-8"
    mail = Mail(config.get('SendAbuse', 'server'),
                port=config.get('SendAbuse', 'port'),
                username=config.get('SendAbuse', 'user'),
                password=config.get('SendAbuse', 'pass'),
                use_tls=False,
                use_ssl=False,
                debug_level=None)
    mail.send(msg)
Exemplo n.º 31
0
 def test_attachment_ascii_filename(self):
     msg = Message(fromaddr='*****@*****.**', to='*****@*****.**')
     msg.attach_attachment('my test doc.txt', 'text/plain', 'this is test')
     self.assert_in('Content-Disposition: attachment;filename='
                    'my test doc.txt', str(msg))
Exemplo n.º 32
0
 def test_subject(self):
     msg = Message('test')
     self.assert_equal(msg.subject, 'test')
     msg = Message('test', fromaddr='*****@*****.**', to='*****@*****.**')
     self.assert_in(msg.subject, str(msg))
Exemplo n.º 33
0
 def test_attach_attachment(self):
     msg = Message()
     msg.attach_attachment('test.txt', 'text/plain', 'this is test')
     self.assert_equal(msg.attachments[0].filename, 'test.txt')
     self.assert_equal(msg.attachments[0].content_type, 'text/plain')
     self.assert_equal(msg.attachments[0].data, 'this is test')
Exemplo n.º 34
0
 def test_plain_text_with_attachments(self):
     msg = Message(fromaddr='*****@*****.**', to='*****@*****.**',
                   subject='hello', body='hello world')
     msg.attach_attachment(content_type='text/plain', data=b'this is test')
     self.assert_in('Content-Type: multipart/mixed', str(msg))
Exemplo n.º 35
0
from sender import JMail, Message
from os import environ

connection_string = environ.get('SMTP_URL')

jmail = JMail(connection_string)

message = Message("Test subject",
                  "*****@*****.**",
                  "This is a test message",
                  fromaddr="*****@*****.**")

jmail.send(message)
Exemplo n.º 36
0
 def test_cc(self):
     msg = Message(fromaddr='*****@*****.**',
                   to='*****@*****.**',
                   cc='*****@*****.**')
     self.assert_in('*****@*****.**', str(msg))
Exemplo n.º 37
0
pwrd = os.environ['GMAIL_PASS']

if __name__ == "__main__":
    with Imbox(imap, username=user, password=pwrd,
               ssl=True, ssl_context=None,
               starttls=False) as imbox:
        drafts = imbox.messages(folder="[Gmail]/Drafts")
        todays_mail = []
        for uid, msg in drafts:
            if 'schedmail' in msg.subject.lower():
                date = msg.subject.lower().split(':')[1]
                today = pendulum.now().date().isoformat()
                subject_date = pendulum.parse(date).date().isoformat()
                if subject_date == today:
                    todays_mail.append(msg)

    mail = Mail('smtp.gmail.com', port=587, username=user,
                password=pwrd, use_tls=True)

    for i in todays_mail:
        msg = Message(i.subject.split(':')[-1])
        msg.fromaddr = (i.sent_from[0]['name'], i.sent_from[0]['email'])
        msg.to = [j['email'] for j in i.sent_to]
        msg.cc = [j['email'] for j in i.cc]
        msg.bcc = [j['email'] for j in i.bcc]
        msg.body = i.body['plain'][0]
        msg.html = i.body['html'][0]
        msg.charset = 'utf-8'

        mail.send(msg)
Exemplo n.º 38
0
#!/usr/bin/env python3

# Before begin you need to change Gmail settings:
# 1. Turn off 2-step verification
# 2. Enable: Allow less secure apps

from sender import Mail, Message

mail = Mail("smtp.gmail.com",
            port=587,
            username="******",
            password="******",
            use_tls=True,
            use_ssl=False,
            debug_level=None)
mail.fromaddr = ("Sender Name", "*****@*****.**")

msg = Message("msg subject")
msg.fromaddr = ("Sender Name", "*****@*****.**")
msg.to = "*****@*****.**"
msg.body = "this is a msg plain text body"
msg.html = "<b>this is a msg text body</b>"
msg.reply_to = "*****@*****.**"
msg.charset = "utf-8"
msg.extra_headers = {}
msg.mail_options = []
msg.rcpt_options = []

# Send message
mail.send(msg)
Exemplo n.º 39
0
        return(output)

    except Exception as e:
        print(e)
        logger.exception('Exception found')


# SMTP log in information
mail = Mail("mail.messagingengine.com",
            port=465, username="******",
            password="******",
            use_tls=False, use_ssl=True, debug_level=None)

# email message object
msg = Message(fromaddr=("Adam Elchert", "*****@*****.**"))

updateFile()
logger.debug('Running UpdateFile()')

if os.path.getsize('fileOutput.txt') != 0:

    # attachment
    with open('fileOutput.txt') as fileOutput:
        attachment = fileOutput.read()

    fileOutput.close()

    # update message object
    msg.fromaddr = ("*****@*****.**")
    msg.body= '{}'.format(attachment)
Exemplo n.º 40
0
    :copyright: (c) 2014 by Shipeng Feng.
    :license: BSD, see LICENSE for more details.
"""
from sender import Mail, Message, Attachment

SMTP_HOST = 'smtp.example.com'
SMTP_USER = '******'
SMTP_PASS = '******'
SMTP_ADDRESS = '*****@*****.**'

mail = Mail(host=SMTP_HOST,
            username=SMTP_USER,
            password=SMTP_PASS,
            fromaddr=SMTP_ADDRESS)

msg01 = Message("Hello01", to="*****@*****.**", body="hello world")

msg02 = Message("Hello02", to="*****@*****.**")
msg02.fromaddr = ('no-reply', '*****@*****.**')
msg02.body = "hello world!"

msg03 = Message("Hello03", to="*****@*****.**")
msg03.fromaddr = (u'请勿回复', '*****@*****.**')
msg03.body = u"你好世界"  # Chinese :)
msg03.html = u"<b>你好世界</b>"

msg04 = Message("Hello04", body="Hello world 04")
msg04.to = "*****@*****.**"
msg04.cc = ["*****@*****.**", "cc02@example"]
msg04.bcc = ["*****@*****.**"]
Exemplo n.º 41
0
# in email_server_config.txt, you enter your email information in this format: smtp.example.com,25,username,password

with open('./email_server_config.txt','r') as f:
	config_content=[]
	for line in f.readlines():
		config_content=line.split(",")
		smtp_server=config_content[0]
		smtp_server_port=config_content[1]
		smtp_server_username=config_content[2]
		smtp_server_password=config_content[3]
		mail=Mail(smtp_server,port=smtp_server_port,username=smtp_server_username,password=smtp_server_password,\
			use_tls=False,use_ssl=False,debug_level=None)

from sender import Message
with open('./to_email_list.txt','r') as f:
	for line in f.readlines():
		msg=Message("email subject",fromaddr=("burness","*****@*****.**"),to=line)
		msg.body = "this is a msg plain text body"
		msg.date = time.time()
		msg.charset = "utf-8"
		msg.extra_headers = {}
		msg.mail_options = []
		msg.rcpt_options = []
		from sender import Attachment
		with open("to_email_list.txt") as f:
			attachment=Attachment("to_email_list.txt","text/txt",f.read())
		msg.attach(attachment)
		mail.send(msg)

print 'To check in your email that ensure it is ok'
Exemplo n.º 42
0
def send_email():
    try:
        data = app.current_request.json_body

        # print(data)

        email = data["email"]
        password = data["password"]
        smtp_server = data["smtp_server"]
        smtp_port = data["smtp_port"]

        toAddress = data["toAddress"]
        fromAddress = data["fromAddress"]
        name = data["name"]
        subject = data["subject"]
        bodyPLAIN = data["bodyPLAIN"]
        bodyHTML = textile(bodyPLAIN)

        mail = Mail(host=smtp_server,
                    port=smtp_port,
                    username=email,
                    password=password,
                    use_ssl=True)

        msg = Message()

        msg.subject = subject
        msg.fromaddr = (name, fromAddress)
        msg.to = toAddress
        msg.body = bodyPLAIN
        msg.html = bodyHTML
        # msg.cc = "*****@*****.**"
        # msg.bcc = ["*****@*****.**", "*****@*****.**"]
        # msg.reply_to = "*****@*****.**"
        msg.date = int(round(time.time()))
        msg.charset = "utf-8"
        msg.extra_headers = {}
        msg.mail_options = []
        msg.rcpt_options = []

        # print(msg)
        # print(type(msg))

        mail.send(msg)

        return Response(body={'sent': True},
                        status_code=200,
                        headers=custom_headers)

    except Exception as error:
        # print("Send Emails Error")
        # print(error)
        return Response(body={'AppError': str(error)},
                        status_code=500,
                        headers=custom_headers)
Exemplo n.º 43
0

SMTP_HOST = 'smtp.example.com'
SMTP_USER = '******'
SMTP_PASS = '******'
SMTP_ADDRESS = '*****@*****.**'


mail = Mail(host=SMTP_HOST, username=SMTP_USER, password=SMTP_PASS,
            fromaddr=SMTP_ADDRESS)


msg01 = Message("Hello01", to="*****@*****.**", body="hello world")


msg02 = Message("Hello02", to="*****@*****.**")
msg02.fromaddr = ('no-reply', '*****@*****.**')
msg02.body = "hello world!"


msg03 = Message("Hello03", to="*****@*****.**")
msg03.fromaddr = (u'请勿回复', '*****@*****.**')
msg03.body = u"你好世界" # Chinese :)
msg03.html = u"<b>你好世界</b>"


msg04 = Message("Hello04", body="Hello world 04")
msg04.to = "*****@*****.**"
msg04.cc = ["*****@*****.**", "cc02@example"]
msg04.bcc = ["*****@*****.**"]