Reputation: 2303
I was trying to create an appointment management system where user can send invitation meeting mail to admin. I can send single mail from user to admin but how could I send an event email from Gmail to outlook
Here is my settings.py code
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = '******'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
here is my views.py
def sendRequest(request):
email = EmailMessage('Subject', 'Body', to=['[email protected]'])
email.send()
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Now I need to send event email not a single mail from my system Gmail account
I do some google about this but not find any proper solution step by step
Upvotes: 2
Views: 2221
Reputation: 2303
First Need To Create a .ics file
BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:Microsoft Exchange Server 2010
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Bangladesh Standard Time
BEGIN:STANDARD
DTSTART:16010101T000000
TZOFFSETFROM:+0600
TZOFFSETTO:+0600
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T000000
TZOFFSETFROM:+0600
TZOFFSETTO:+0600
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
ORGANIZER;CN=dekkoappoint:MAILTO:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-
ACTION;RSVP=TRUE;[email protected]:MAILTO:[email protected]
DESCRIPTION;LANGUAGE=en-US:Hi This is a test mail\n
UID:040000008200E00074C5B7101A82E008000000009CCD2D80E57BD401000000000000000
010000000F02E168DB7BF3A4BAC1FAE1547D716BE
SUMMARY;LANGUAGE=en-US:Test Event
DTSTART;TZID=Bangladesh Standard Time:20181115T130000
DTEND;TZID=Bangladesh Standard Time:20181115T140000
CLASS:PUBLIC
PRIORITY:5
DTSTAMP:20181114T064433Z
TRANSP:OPAQUE
STATUS:CONFIRMED
SEQUENCE:0
LOCATION;LANGUAGE=en-US:Dhaka University Area (Dhaka University Area Dhaka\
, Bangladesh)
X-MICROSOFT-CDO-APPT-SEQUENCE:0
X-MICROSOFT-CDO-OWNERAPPTID:2116776604
X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-CDO-INSTTYPE:0
X-MICROSOFT-DONOTFORWARDMEETING:FALSE
X-MICROSOFT-DISALLOW-COUNTER:FALSE
X-MICROSOFT-LOCATIONDISPLAYNAME:Dhaka University Area
X-MICROSOFT-LOCATIONSOURCE:Device
X-MICROSOFT-LATITUDE:23.7303
X-MICROSOFT-LONGITUDE:90.3933
X-MICROSOFT-LOCATIONCITY:Dhaka University Area
X-MICROSOFT-LOCATIONSTATE:Dhaka
X-MICROSOFT-LOCATIONCOUNTRY:Bangladesh
X-MICROSOFT-LOCATIONS:[{"DisplayName":"Dhaka University Area"\,"LocationAnn
otation":""\,"LocationSource":3\,"LocationUri":""\,"Latitude":23.7303\,"Lo
ngitude":90.3933\,"LocationStreet":""\,"LocationCity":"Dhaka University Ar
ea"\,"LocationState":"Dhaka"\,"LocationCountry":"Bangladesh"\,"LocationPos
talCode":""\,"LocationFullAddress":""}]
BEGIN:VALARM
DESCRIPTION:REMINDER
TRIGGER;RELATED=START:-PT15M
ACTION:DISPLAY
END:VALARM
END:VEVENT
END:VCALENDAR
After that in view.py
from django.core.mail import EmailMessage
def sendRequest(request):
email = EmailMessage('Subject', 'email body', '[email protected]', ['[email protected]'])
email.attach_file('assets/invite.ics', 'text/calendar')
email.send()
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Upvotes: 1
Reputation: 3610
What you can do is to create a .ics
file with the invitation information (you may use a Django template to write a .ics
file or just generate it using plain Python code).
You can see the .ics
file specification and read more about it here:
https://en.wikipedia.org/wiki/ICalendar
Then you could just attach this .ics
file to your email message:
email = EmailMessage('Meeting invitation', 'Email body...', '[email protected]', ['[email protected]', ])
email.attach('invite.ics', invite_file_content, 'text/calendar')
email.send()
Alternatively you can use this third-party app django-cal
Maybe this post can also give you some insights on the issue: How can I get a meeting invitation to integrate properly with Gmail/Google Apps?
Upvotes: 3