Anexando um arquivo ical a um email do django
Existem muitos exemplos de como anexar um arquivo a um email, mas não consigo encontrar um exemplo de como anexar uma instância MIMEBase.
Nos documentos: anexos "Podem ser instâncias de email.MIMEBase.MIMEBase ou (nome do arquivo, conteúdo, tipo mimetico) triplos".
Então, eu estou gerando um arquivo iCal em uma função muito bem:
def ical()
cal = vobject.iCalendar()
cal.add('method').value = 'PUBLISH' # IE/Outlook needs this
vevent = cal.add('vevent')
vevent.add('dtstart').value = self.course.startdate
vevent.add('dtend').value = self.course.startdate
vevent.add('summary').value='get details template here or just post url'
vevent.add('uid').value=str(self.id)
vevent.add('dtstamp').value = self.created
icalstream = cal.serialize()
response = HttpResponse(icalstream, mimetype='text/calendar')
response['Filename'] = 'shifts.ics' # IE needs this
response['Content-Disposition'] = 'attachment; filename=shifts.ics'
return response
Mas isto não está funcionando:
myicalfile = ical()
message.attach(myicalfile)