smtplib send caleneder email

Solutions on MaxInterview for smtplib send caleneder email by the best coders in the world

showing results for - "smtplib send caleneder email"
Clotilde
03 Jun 2018
1import smtplib
2from email.MIMEMultipart import MIMEMultipart
3from email.MIMEBase import MIMEBase
4from email.MIMEText import MIMEText
5from email.Utils import COMMASPACE, formatdate
6from email import Encoders
7import os,datetime
8
9CRLF = "\r\n"
10login = "yourloging@googlemail.com"
11password = "yourpassword"
12attendees = ["first@gmail.com",     "second@example.com","third@hotmail.com"]
13organizer = "ORGANIZER;CN=organiser:mailto:first"+CRLF+" @gmail.com"
14fro = "nickname <first@gmail.com>"
15
16ddtstart = datetime.datetime.now()
17dtoff = datetime.timedelta(days = 1)
18dur = datetime.timedelta(hours = 1)
19ddtstart = ddtstart +dtoff
20dtend = ddtstart + dur
21dtstamp = datetime.datetime.now().strftime("%Y%m%dT%H%M%SZ")
22dtstart = ddtstart.strftime("%Y%m%dT%H%M%SZ")
23dtend = dtend.strftime("%Y%m%dT%H%M%SZ")
24
25description = "DESCRIPTION: test invitation from pyICSParser"+CRLF
26attendee = ""
27for att in attendees:
28    attendee += "ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-    PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE"+CRLF+" ;CN="+att+";X-NUM-GUESTS=0:"+CRLF+" mailto:"+att+CRLF
29ical = "BEGIN:VCALENDAR"+CRLF+"PRODID:pyICSParser"+CRLF+"VERSION:2.0"+CRLF+"CALSCALE:GREGORIAN"+CRLF
30ical+="METHOD:REQUEST"+CRLF+"BEGIN:VEVENT"+CRLF+"DTSTART:"+dtstart+CRLF+"DTEND:"+dtend+CRLF+"DTSTAMP:"+dtstamp+CRLF+organizer+CRLF
31ical+= "UID:FIXMEUID"+dtstamp+CRLF
32ical+= attendee+"CREATED:"+dtstamp+CRLF+description+"LAST-MODIFIED:"+dtstamp+CRLF+"LOCATION:"+CRLF+"SEQUENCE:0"+CRLF+"STATUS:CONFIRMED"+CRLF
33ical+= "SUMMARY:test "+ddtstart.strftime("%Y%m%d @ %H:%M")+CRLF+"TRANSP:OPAQUE"+CRLF+"END:VEVENT"+CRLF+"END:VCALENDAR"+CRLF
34
35eml_body = "Email body visible in the invite of outlook and outlook.com but not google calendar"
36eml_body_bin = "This is the email body in binary - two steps"
37msg = MIMEMultipart('mixed')
38msg['Reply-To']=fro
39msg['Date'] = formatdate(localtime=True)
40msg['Subject'] = "pyICSParser invite"+dtstart
41msg['From'] = fro
42msg['To'] = ",".join(attendees)
43
44part_email = MIMEText(eml_body,"html")
45part_cal = MIMEText(ical,'calendar;method=REQUEST')
46
47msgAlternative = MIMEMultipart('alternative')
48msg.attach(msgAlternative)
49
50ical_atch = MIMEBase('application/ics',' ;name="%s"'%("invite.ics"))
51ical_atch.set_payload(ical)
52Encoders.encode_base64(ical_atch)
53ical_atch.add_header('Content-Disposition', 'attachment; filename="%s"'%("invite.ics"))
54
55eml_atch = MIMEBase('text/plain','')
56Encoders.encode_base64(eml_atch)
57eml_atch.add_header('Content-Transfer-Encoding', "")
58
59msgAlternative.attach(part_email)
60msgAlternative.attach(part_cal)
61
62mailServer = smtplib.SMTP('smtp.gmail.com', 587)
63mailServer.ehlo()
64mailServer.starttls()
65mailServer.ehlo()
66mailServer.login(login, password)
67mailServer.sendmail(fro, attendees, msg.as_string())
68mailServer.close()
69