0
我正在使用httplib2和Mailgun API來發送電子郵件附件,這是我使用Google Drive下載的,電子郵件正在發送但沒有附件..以下是我的代碼..如何用Mailgun使用python httplib2發送電子郵件附件
DRIVE = discovery.build('drive', 'v3', http=http_auth)
request = DRIVE.files().export_media(fileId=file_id, mimeType='application/pdf')
fh = io.BytesIO()
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
logging.info("Download %d%%." % int(status.progress() * 100))
messages = {
"from": sender,
"to": recipient,
"subject": 'Attachment Mail from Mailgun',
"text": 'Testing',
"attachment": fh.getvalue()
}
url = URL
data = {
"from": messages['from'],
"to": messages['to'],
"subject": messages['subject'],
"text": messages['text'],
"attachment": messages['attachment']
}
pl = urllib.urlencode(data)
http = httplib2.Http()
http.add_credentials('api', API)
resp, content = http.request(
url, 'POST', pl,
headers={"Content-Type": "application/x-www-form-urlencoded"})