Mailgun API와 함께 httplib2를 사용하여 Google 드라이브를 사용하여 다운로드 한 전자 메일 첨부 파일을 보내고 있습니다. 전자 메일은 첨부 파일없이 보내지 만 .. 아래 코드는Python을 사용하여 전자 메일 첨부 파일을 Mailgun과 함께 보내는 방법
입니다.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"})