I'm working in an app that provides you a file with different events (icalendar file) and when I want to send to my Gmail account, adding METHOD='REQUEST'
only I can add automatically the first event in my gmail account. Maybe the problem is with Gmail, but I think that's improbably that you only can create a file with one event and send it, because create a file with five or six events it's not so hard to see. I attach here the code of the .py program that send the email:
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import encoders
import os
fromaddr = "adress@gmail.com"
toaddr = mail.strip()
msg = MIMEMultipart('alternative')
msg['From'] = "fromaddr"
msg['To'] = 'receiver adress'
msg['Subject'] = "Calendar"
body = """The hole body"""
msg.attach(MIMEText(body, "html"))
filename = "file.ics"
part = MIMEBase('text', 'calendar',method='REQUEST',name=filename) #method ='REQUEST' only provide me the possibility of adding 1 event, not 5
part.set_payload(cal.to_ical()) #cal is created in a previous step, multiple events
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(part)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()