forked from havannavar/python-calendar-invite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventInvitation.py
More file actions
76 lines (63 loc) · 2.56 KB
/
eventInvitation.py
File metadata and controls
76 lines (63 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# encoding=utf8
'''
@author: sats
'''
import smtplib
from email.utils import formatdate
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import Encoders
import os, datetime
config = fileutil.social
def send_invite(param):
CRLF = "\r\n"
attendees = param['to']
attendees = ""
try:
for att in param['to']:
attendees += "ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="+att+";X-NUM-GUESTS=0:mailto:"+att+CRLF
except Exception as e:
print e
msg = MIMEMultipart('mixed')
msg['Reply-To']=fro
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = 'Satish:Meeting invitation from Satihs'
msg['From'] = fro
msg['To'] = attendees
__location__ = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
f= os.path.join(__location__, 'invite.ics')
ics_content = open(f).read()
try:
replaced_contents = ics_content.replace('startDate', param['startDate'])
replaced_contents = replaced_contents.replace('endDate', param['endDate'])
replaced_contents = replaced_contents.replace('telephonic', param['location'])
replaced_contents = replaced_contents.replace('now', datetime.datetime.now().strftime("%Y%m%dT%H%M%SZ"))
except Exception as e:
log.warn(e)
if param.get('describe') is not None:
replaced_contents = replaced_contents.replace('describe', param.get('describe'))
else:
replaced_contents = replaced_contents.replace('describe', '')
replaced_contents = replaced_contents.replace('attend', msg['To'])
replaced_contents = replaced_contents.replace('subject', param['subject'])
part_email = MIMEText(replaced_contents,'calendar;method=REQUEST')
msgAlternative = MIMEMultipart('alternative')
ical_atch = MIMEBase('text/calendar',' ;name="%s"'%"invitation.ics")
ical_atch.set_payload(replaced_contents)
Encoders.encode_base64(ical_atch)
ical_atch.add_header('Content-Disposition', 'attachment; filename="%s"'%f)
msgAlternative.attach(part_email)
msgAlternative.attach(ical_atch)
msg.attach(msgAlternative)
mailServer = smtplib.SMTP('smtp.mandrillapp.com', 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login('smtp-username', 'smtp-password')
mailServer.sendmail(fro, param['to'], msg.as_string())
mailServer.close()