Пример #1
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)
Пример #2
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
Пример #3
0
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)
    msg.to = ('*****@*****.**')
    msg.subject=('Tweets from {}'.format(strftime('%B %d')))
    mail.send(msg)
    logger.info('Sent Email')
    logger.debug('Debug: %s', [msg])


    os.remove('fileOutput.txt')
    logger.debug('fielOutput.txt removed')

else:
    logger.debug('No tweet updates - No mail sent')
    os.remove('fileOutput.txt')
    logger.debug('fileOutput.txt removed')
    sys.exit()