0

While sending meeting invite using "icalendar" library I am facing issue with time zone difference in Gmail and outlook mails. When I am sending meeting invitation to outlook it automatically changing time zone IST to GMT. Please help me out to solve this issue.

The below code I used for sending meeting invitation using "icalendar" but it is not working for outlook mail. It is sending meeting invitation for outlook mails but timezone is differing. Please any one help me to achieve it.

Thank you

from email import encoders
import smtplib
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import datetime as dt
import datetime
from email.mime.multipart import MIMEMultipart

import icalendar
import pytz
login = "salimabegum534@gmail.com"
password = "********"
organiser_email = "example@gmail.com"
atendee_email = "example2@gmail.com"
subj = "Test mail invitation"
description = "Test mail invitation description"
start_hour = 1
start_minute = 0
# location =
date_time = datetime.datetime.now()
tz = pytz.timezone("Asia/kolkata")

start = tz.localize(dt.datetime.combine(date_time, dt.time(start_hour, start_minute, 0)))

# Imagine this function is part of a class which provides the necessary config data
# Timezone to use for our dates - change as needed
# start = tz.localize(date_time)
# Build the event itself
cal = icalendar.Calendar()
cal.add('prodid', '-//My calendar application//example.com//')
cal.add('version', '2.0')
cal.add('method', "REQUEST")
event = icalendar.Event()
event.add('attendee', atendee_email)
event.add('organizer', organiser_email)
event.add('status', "confirmed")
event.add('category', "Event")
event.add('summary', subj)
event.add('description', description)
# event.add('location', location)
event.add('dtstart', start)
event.add('dtend', tz.localize(dt.datetime.combine(date_time, dt.time(start_hour + 1, start_minute, 0))))
event.add('dtstamp', tz.localize(dt.datetime.combine(date_time, dt.time(6, 0, 0))))
event.add('dtstart', start)
# event.add('dtend', tz.localize(date_time))
event.add('dtstamp', tz.localize(date_time))
# event['uid'] = self.get_unique_id() # Generate some unique ID
event.add('priority', 5)
event.add('sequence', 1)
event.add('created', tz.localize(date_time))

# Add a reminder
alarm = icalendar.Alarm()
alarm.add("action", "DISPLAY")
alarm.add('description', "Reminder")
# The only way to convince Outlook to do it correctly
# alarm.add("TRIGGER;RELATED=START", "-PT{0}H".format(reminder_hours))
event.add_component(alarm)
cal.add_component(event)

# Build the email message and attach the event to it
msg = MIMEMultipart("alternative")

msg["Subject"] = subj
msg["From"] = organiser_email
msg["To"] = atendee_email
msg["Content-class"] = "urn:content-classes:calendarmessage"

msg.attach(MIMEText(description))

filename = "invite.ics"
part = MIMEBase('text', "calendar", method="REQUEST", name=filename)
part.set_payload(cal.to_ical() )
encoders.encode_base64(part)
part.add_header('Content-Description', filename)
part.add_header("Content-class", "urn:content-classes:calendarmessage")
part.add_header("Filename", filename)
part.add_header("Path", filename)
msg.attach(part)

# Send the email out
# s = smtplib.SMTP('localhost')
# s.sendmail(msg["From"], [msg["To"]], msg.as_string())
# s.quit()


mailServer = smtplib.SMTP('smtp.gmail.com', 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(login, password)
mailServer.sendmail(msg["From"], [msg["To"]], msg.as_string())
mailServer.close()

0 Answers0