Based flask mail service

First, demand:

When the newly recruited staff, received a demand for research and development, you need a mail server, unified entrance sent as daily R & D work in the mail, so I thought I could write a flask based.

Second, the code:

Specific reference to the following code git Address:
https://github.com/f1017746640/fmax.git

Third, the interface testing:

Interface test code also git repository.
3.1 No attachments:

#!/usr/bin/env python
# encoding: utf-8
"""
   > FileName: mailapi.py
   > Author: FZH
   > Mail: [email protected]
   > CreatedTime: 2020-03-22 13:20
"""
import os
import requests

url = "http://127.0.0.1:5000/fmax"

def mail_send():
    data = {'mail_to': '[email protected]',
            'mail_title': 'TEST_TITLE',
            'mail_body': '接口更新完毕'}
    files = []
    response = requests.request("POST",
                                url,
                                data=data,
                                files=files)
    return response.text.encode('utf8')

if __name__ == '__main__':
    mail_send()

Test Results:

3.2 There are accessories:

#!/usr/bin/env python
# encoding: utf-8
"""
   > FileName: mailapi.py
   > Author: FZH
   > Mail: [email protected]
   > CreatedTime: 2020-03-22 13:20
"""
import os
import requests

url = "http://127.0.0.1:5000/fmax"

def mail_send_append():
    data = {'mail_to': '[email protected]',
            'mail_title': 'TEST_TITLE',
            'mail_body': '接口更新完毕'}

    des_file = os.path.join(os.path.dirname(__file__),
                            'fmax.xlsx')
    files = {'file': open(des_file, 'rb')}
    headers = {
      'Content-Type': 'multipart/form-data'
    }
    response = requests.request("POST",
                                url,
                                data=data,
                                files=files)
    return response.text.encode('utf8')

if __name__ == '__main__':
    mail_send_append()

Test Results:

Guess you like

Origin www.cnblogs.com/fengzhihai/p/12545937.html