i need help for send a mail in the Lotus Notes using python, appear that the win32com can do it, but i don't found any complete example or tutorial. My idea is a simple function like it:
from win32com.client import Dispatch
import smtplib
def SendMail(subject, text, user):
session = Dispatch('Lotus.NotesSession')
session.Initialize('???')
db = session.getDatabase("", "")
db.OpenMail();
Some suggestion? Thanks!
Below is some code that I have used for this purpose for several years:
from __future__ import division, print_function
import os, uuid
import itertools as it
from win32com.client import DispatchEx
import pywintypes # for exception
def send_mail(subject,body_text,sendto,copyto=None,blindcopyto=None,
attach=None):
session = DispatchEx('Lotus.NotesSession')
session.Initialize('your_password')
server_name = 'your/server'
db_name = 'your/database.nsf'
db = session.getDatabase(server_name, db_name)
if not db.IsOpen:
try:
db.Open()
except pywintypes.com_error:
print( 'could not open database: {}'.format(db_name) )
doc = db.CreateDocument()
doc.ReplaceItemValue("Form","Memo")
doc.ReplaceItemValue("Subject",subject)
# assign random uid because sometimes Lotus Notes tries to reuse the same one
uid = str(uuid.uuid4().hex)
doc.ReplaceItemValue('UNIVERSALID',uid)
# "SendTo" MUST be populated otherwise you get this error:
# 'No recipient list for Send operation'
doc.ReplaceItemValue("SendTo", sendto)
if copyto is not None:
doc.ReplaceItemValue("CopyTo", copyto)
if blindcopyto is not None:
doc.ReplaceItemValue("BlindCopyTo", blindcopyto)
# body
body = doc.CreateRichTextItem("Body")
body.AppendText(body_text)
# attachment
if attach is not None:
attachment = doc.CreateRichTextItem("Attachment")
for att in attach:
attachment.EmbedObject(1454, "", att, "Attachment")
# save in `Sent` view; default is False
doc.SaveMessageOnSend = True
doc.Send(False)
if __name__ == '__main__':
subject = "test subject"
body = "test body"
sendto = ['abc#def.com',]
files = ['/path/to/a/file.txt','/path/to/another/file.txt']
attachment = it.takewhile(lambda x: os.path.exists(x), files)
send_mail(subject, body, sendto, attach=attachment)
If your company is set up such a way that a host IP address and Port is sufficient to send an email, then use the following:
import smtplib
from email.mime.base import MIMEBase
from email import encoders
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def emailReport(attach_path,file_name,From,to,cc=None):
msg = MIMEMultipart()
msg['Subject'] = file_name
msg['From'] = From
msg['To'] = ", ".join(to)
msg['CC'] = ", ".join(cc)
msg.attach(MIMEText("****Body of your email****\n"))
#For multiple attachments repeat/loop the following:
part = MIMEBase('application', "octet-stream")
part.set_payload(open(attach_path.format(file_name), "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename=%s' % file_name)
msg.attach(part)
#Repeat stops here....
s = smtplib.SMTP(host='xxx.xxx.xx.x',port=xx) #Enter your IP and port here
s.sendmail(From,to+cc,msg.as_string())
s.quit()
to=['Person1#email.com', 'Person2#email.com']
cc=['Person3#email.com', 'Person4#email.com']
From='Your#email.com'
attach_path=r'C:\Users\Desktop\Temp'
file_name='Test.xlsx'
emailReport(attach_path,file_name,From,to,cc)
Related
import smtplib
import mechanize
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
def sem():
if not os.path.isfile('key.txt'):
print('below details are req to send report')
gmail_user = input('enter your email=')
gmail_app_password = input('enter your email password=')
print('pls accept the login in your gmail account ')
ke = open('key.txt',mode="w+")
ke.write(gmail_user)
ke.write(':')
ke.write(gmail_app_password)
ke.close()
if not os.path.isfile('sto.txt'):
gmai = input('enter the email to send report=')
ke = open('sto.txt',mode="w+")
ke.write(gmai)
ke.close()
with open('key.txt',mode="r")as f:
ds=f.readlines()
d=''.join(ds)
r=d.split(':')
with open('sto.txt',mode="r")as f:
ds=f.readlines()
f=ds
print(f)
gmail_user = r[0]
gmail_app_password = r[1]
sent_from = gmail_user
sent_to = ds
sent_subject = "hey amo lio ,how are ?"
sent_body = ("Hey, what's up? friend!")
email_text = """\
To: %s
Subject: %s
%s
""" % (", ".join(sent_to), sent_subject, sent_body)
mail = MIMEMultipart()
mail["Subject"] = sent_subject
mail["From"] = sent_from
mail["To"] = sent_to
mail.attach[MIMEText(sent_body,'html')]
ctype, encoding = mimetypes.guess_type(_file)
maintype, subtype = ctype.split('/', 1)
fp = open("./data/mood.txt")
msg = MIMEText(fp.read(), _subtype=subtype)
fp.close()
filename = os.path.basename(_file)
msg.add_header('Content-Disposition', 'attachment', filename=filename)
mail.attach(msg)
print('done')
server.sendmail(sent_from, sent_to, mail.as_string())
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_app_password)
server.sendmail(sent_from, sent_to, email_text)
server.close()
print('Email sent!')
except Exception as exception:
print("Error: %s!\n\n" % exception)
sem()
How can I attach the helloword.txt file in this email? This code is working fine, I just want to send an attachment along with it. This code lets me me send the body without any attachment. Also, how do I encrypt the key.txt file which store email address and password, and to send email it it requires the password to be entered (diff pass)?
You need to use the 'MIMEMultipart' module to attach files.
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
mail = MIMEMultipart()
mail["Subject"] = sent_subject
mail["From"] = sent_from
mail["To"] = sent_to
mail.attach(MIMEText(sent_body,'html'))
ctype, encoding = mimetypes.guess_type(_file)
maintype, subtype = ctype.split('/', 1)
fp = open("/path/to/attachment/file.txt")
# If file mimetype is video/audio use respective email.mime module.
# Here assuming 'maintype' == 'text' we will use MIMEText
msg = MIMEText(fp.read(), _subtype=subtype)
fp.close()
filename = os.path.basename(_file)
msg.add_header('Content-Disposition', 'attachment', filename=filename)
mail.attach(msg)
server.sendmail(sent_from, sent_to, mail.as_string())
import smtplib
import mechanize
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import mimetypes
import pdb
def email:
sender_address = gmail_user
#make it input
receiver_address = gmail_user
#Setup the MIME
fromaddr = gmail_user
sendto = gmail_app_password
sender_pass = gmail_app_password = input('enter your email password')
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = sendto
msg['Subject'] = 'This is cool'
body = "this is the body of the text message"
msg.attach(MIMEText(body, 'plain'))
filename = 'mood.txt'
attachment = open('./data/mood.txt', 'rb')
part = MIMEBase('application', "octet-stream")
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename= %s' % filename)
msg.attach(part)
smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
smtpObj.ehlo()
smtpObj.starttls()
smtpObj.login(gmail_user, gmail_app_password)
text = msg.as_string()
smtpObj.sendmail(fromaddr, sendto , text)
smtpObj.quit() # attach the instance 'p' to instance 'msg'
here is perfect working code for sending email
I am new to AWS Lambda function.
I wanted to send email to multiple recipients. I am able to send email to single email address but not multiple email ids and shows error.
I just refered the amazon documentation page and wrote the below code.
I am using environmental variable runteam and it has values like ['aaa#xyz.com','bbb#xyz.com','ccc#xyz.com']
import boto3
import os
import os, sys, subprocess
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
def lambda_handler(event,context):
ses = boto3.client("ses")
s3 = boto3.client("s3")
runemail = os.environ['runteam']
for i in event["Records"]:
action = i["eventName"]
#ip = i["requestParameters"]["soruceIPAddress"]
bucket_name = i["s3"]["bucket"]["name"]
object = i["s3"]["object"]["key"]
fileObj = s3.get_object(Bucket = bucket_name, Key = object)
file_content = fileObj["Body"].read()
sender = "test#xyz.com"
to = runemail
subject = str(action) + 'Event from ' + bucket_name
body = """
<br>
This email is to notify regarding {} event
This object {} is created
""".format(action,object)
msg = MIMEMultipart('alternative')
msg["Subject"] = subject
msg["From"] = sender
msg["To"] = ', '.join(runemail)
body_txt = MIMEText(body, "html")
attachment = MIMEApplication(file_content)
attachment.add_header("Content-Disposition","attachment", filename = "ErrorLog.txt")
msg.attach(body_txt)
msg.attach(attachment)
response = ses.send_raw_email(Source = sender, Destinations = rumemail, RawMessage = {"Data": msg.as_string()})
return "Thanks"
I think everything seems to be right regarding the email sending code. The error lies in your program where the way you store your environ variable.
It should be stored as runteam="aaa#xyz.com bbb#xyz.com ccc#xyz.com" (notice the space between each email)
Then use this variable as
rumemail = os.environ['runteam'].split()
msg["To"] = ', '.join(runemail)
response = ses.send_raw_email(Source = sender, Destinations = rumemail, RawMessage = {"Data": msg.as_string()})
This line:
msg["To"] = ', '.join(runemail)
is expecting a Python list, not a string. I suggest you add a debug line after it to see what you are actually sending the system.
I would recommending passing your environment variable as:
person#address.com, person2#address.com, person3#address.com
Then, use:
msg["To"] = runemail
Removing/commenting out the following line should fix the issue:
msg["To"] = ', '.join(runemail)
By the above line, you are converting a list to a string. However, Destinations attribute is looking for a list.
I'm just looking to send an email with 3 csv file attachments. When i get it to run, trying a solution i found on here, it gives me a BIN file instead of the 3 files. Or, trying another solution, it will only send the last of the the 3 files. When i run the code below, its gives me TypeError: add.header() takes 3 positional arguments but 4 were given.
I understand that it can be done with a function, but i'm not sure how to have it pull all three files into it. I've spent numerous hours trying to figure it out.
Posting it on here is my last resort. I appreciate any help in finding a solution.
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import time
import os
msg = MIMEMultipart()
msg['From'] = EMAIL_FROM
msg['To'] = ", ".join(RECIPIENT_LIST)
msg['Subject'] = 'Louisiana Contractors List'
#email content
message = """<html>
<body>
Attached is the Louisiana Contractors Spreadsheet.
<br><br>
Let me know if you have any questions
</body>
</html>
"""
msg.attach(MIMEText(message, 'html'))
files = [
'C:/Users/rkrouse/Downloads/search-results.csv',
'C:/Users/rkrouse/Downloads/search-results(1).csv',
'C:/Users/rkrouse/Downloads/search-results(2).csv']
for a_file in files:
attachment = open(a_file, 'rb')
part = MIMEBase('application','octet-stream')
part.set_payload((attachment).read())
part.add_header('Content-Disposition', 'attachment', a_file = os.path.basename('C:/Users/rkrouse/Downloads/search-results.csv'))
encoders.encode_base64(part)
msg.attach(part)
for a_file in files:
attachment = open(a_file, 'rb')
part = MIMEBase('application','octet-stream')
part.set_payload((attachment).read())
part.add_header('Content-Disposition', 'attachment', a_file = os.path.basename('C:/Users/rkrouse/Downloads/search-results(1).csv'))
encoders.encode_base64(part)
msg.attach(part)
for a_file in files:
attachment = open(a_file, 'rb')
part = MIMEBase('application','octet-stream')
part.set_payload(attachment.read())
part.add_header('Content-Disposition', 'attachment', a_file = os.path.basename('C:/Users/rkrouse/Downloads/search-results(2).csv'))
encoders.encode_base64(part)
msg.attach(part)
#sends email
smtpserver = smtplib.SMTP(EMAIL_SERVER, EMAIL_PORT)
smtpserver.sendmail(EMAIL_FROM, RECIPIENT_LIST, msg.as_string())
smtpserver.quit()
Updated tested solution:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import time
import os
msg = MIMEMultipart()
msg['From'] = EMAIL_FROM
msg['To'] = ", ".join(RECIPIENT_LIST)
msg['Subject'] = 'Louisiana Contractors List'
#email content
message = """<html>
<body>
Attached is the Louisiana Contractors Spreadsheet.
<br><br>
Let me know if you have any questions
</body>
</html>
"""
msg.attach(MIMEText(message, 'html'))
files = [
'C:/Users/rkrouse/Downloads/search-results.csv',
'C:/Users/rkrouse/Downloads/search-results(1).csv',
'C:/Users/rkrouse/Downloads/search-results(2).csv']
for a_file in files:
attachment = open(a_file, 'rb')
file_name = os.path.basename(a_file)
part = MIMEBase('application','octet-stream')
part.set_payload(attachment.read())
part.add_header('Content-Disposition',
'attachment',
filename=file_name)
encoders.encode_base64(part)
msg.attach(part)
#sends email
smtpserver = smtplib.SMTP(EMAIL_SERVER, EMAIL_PORT)
smtpserver.sendmail(EMAIL_FROM, RECIPIENT_LIST, msg.as_string())
smtpserver.quit()
As you can see you need to specify the filename in the base64 encoding.
Also you are iterating the files three time.
A for loop is used to go through a list, set, array, etc. One for loop (as all attachments are in one list) should be enough.
Following is the simple snippet that I used to send an email to multiple people with multiple file attachments.
# -*- coding: utf-8 -*-
import smtplib
import mimetypes
from email.mime.multipart import MIMEMultipart
from email import encoders
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
import ntpath
sender_address = 'vijay.anand#xxxx.com'
default_subject = 'Test email from {}'.format(sender_address)
smtp_server_address = '10.111.41.25'
smtp_port_number = 25
default_message = message = """<html>
<body>
Attached is the Louisiana Contractors Spreadsheet.
<br><br>
Let me know if you have any questions
</body>
</html>
"""
def send_by_smtp(to=None, cc=None, bcc=None, subject=None, attachments=None, attachment_type='plain'):
"""
Snippet to send an email to multiple people along with multiple attachments.
:param to: list of emails
:param cc: list of emails
:param bcc: list of emails
:param subject: Email Subject
:param attachments: list of file paths
:param attachment_type: 'plain' or 'html'
:return: None
"""
email_from = sender_address
email_to = list()
files_to_send = attachments
msg = MIMEMultipart()
msg["From"] = email_from
if to:
to = list(set(to))
email_to += to
msg["To"] = ', '.join(to)
if cc:
cc = list(set(cc))
email_to += cc
msg["Cc"] = ', '.join(cc)
if bcc:
bcc = list(set(bcc))
email_to += bcc
msg["Bcc"] = ', '.join(bcc)
if subject:
msg["Subject"] = subject
msg.preamble = subject
else:
msg["Subject"] = default_subject
msg.preamble = default_subject
body = default_message
msg.attach(MIMEText(body, attachment_type))
if files_to_send:
for file_to_send in files_to_send:
content_type, encoding = mimetypes.guess_type(file_to_send)
if content_type is None or encoding is not None:
content_type = "application/octet-stream"
maintype, subtype = content_type.split("/", 1)
if maintype == "text":
with open(file_to_send) as fp:
# Note: we should handle calculating the charset
attachment = MIMEText(fp.read(), _subtype=subtype)
elif maintype == "image":
with open(file_to_send, "rb") as fp:
attachment = MIMEImage(fp.read(), _subtype=subtype)
elif maintype == "audio":
with open(file_to_send, "rb")as fp:
attachment = MIMEAudio(fp.read(), _subtype=subtype)
else:
with open(file_to_send, "rb") as fp:
attachment = MIMEBase(maintype, subtype)
attachment.set_payload(fp.read())
encoders.encode_base64(attachment)
attachment.add_header("Content-Disposition", "attachment", filename=ntpath.basename(file_to_send))
msg.attach(attachment)
try:
smtp_obj = smtplib.SMTP(host=smtp_server_address, port=smtp_port_number, timeout=300)
smtp_obj.sendmail(from_addr=email_from, to_addrs=list(set([email_from] + email_to)), msg=msg.as_string())
print("Successfully sent email to {}".format(str(email_to)))
smtp_obj.quit()
return True
except smtplib.SMTPException:
print("Error: unable to send email")
return False
if __name__ == '__main__':
print('Send an email using Python')
result = send_by_smtp(to=['vijay#xxxx.com', 'tha#xxx.com'],
cc=['anandp#xxxx.com', 'nitha#xxxx.com'],
bcc=['vij#xxxx.com', 'Sun#xxxx.com'],
subject='Louisiana Contractors List',
attachments=['test.txt', '1.JPG', '2.PNG', '3.PNG', '4.PNG'],
attachment_type='html')
if result:
print('Email Sent Successfully')
else:
print('Email Sending Failed')
I am trying to get the results of a MYSQL query into the body of an email and also as a csv or xls attachment.
My code below works and sends the email only problem is if the results from the MYSQL query are more than a row only the first row shows up in the email.
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os
import MySQLdb
import string
import datetime
import time
today = (time.strftime("%m/%d/%Y"))
#print today
db = MySQLdb.connect(host="-----.com", # your host, usually localhost
user="----", # your username
passwd="-------", # your password
db="dailies") # name of the data base
cursor49=db.cursor()
cursor49.execute("SELECT PLACEMENT_NAME FROM dailies.pub_cpm join placement ON placement.PLACEMENT_id = pub_cpm.PLACEMENT_ID where date(pub_cpm.created) = date(now())")
results49 = cursor49.fetchone()
# Commit your changes in the database
db.commit()
# disconnect from server
db.close()
results50 = "Latest Pub CPM Name(s): %s" % (results49)
gmail_user = "------#gmail.com"
gmail_pwd = "g---a"
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
to = ['-----#g-----']
msg = MIMEMultipart()
msg['From'] = gmail_user
msg['To'] = ", ".join(to)
msg['Subject'] = "Database Alerts: %s" % (today)
body = results50
msg.attach(MIMEText(body, 'plain'))
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
text = msg.as_string()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to, text)
# Should be mailServer.quit(), but that crashes...
mailServer.close()
There are a couple changes you need to make. First, you need to change your fetchone() call to a fetchall() call. This will return all results from your SELECT query.
Next, you want to write these to a CSV file. Let's do that using the results from our query above:
results49 = cursor.fetchall()
fp = open('/tmp/file_name.csv', 'w') # You pick a name, it's temporary
attach_file = csv.writer(fp)
attach_file.writerows(results49)
fp.close()
At this point, you have a file in /tmp/file_name.csv (or what ever path and name you picked) that contains your CSV results. The final step is to attach this to an email.
msg = MIMEMultipart()
msg['From'] = gmail_user
msg['To'] = ", ".join(to)
msg['Subject'] = "Database Alerts: %s" % (today)
body = results50
part = MIMEBase('application', "octet-stream")
part.set_payload(open("/tmp/file_name.csv", "rb").read()) # This is the same file name from above
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="/tmp/file_name.csv"')
msg.attach(part)
I changed your msg.attach() function and utilized code from another question.
Once this is done, you still have a file in /tmp/file_name.csv. You can delete this safely at this point.
I'm trying to email multiple recipients using the pyton script below. I've searched the forum for answers, but have not been able to implement any of them correctly. If anyone has a moment to review my script and spot/resolve the problem it would be greatly appreciated.
Here's my script, I gather my issue is in the 'sendmail' portion, but can't figure out how to fix it:
gmail_user = "sender#email.com"
gmail_pwd = "sender_password"
recipients = ['recipient1#email.com','recipient2#email.com']
def mail(to, subject, text, attach):
msg = MIMEMultipart()
msg['From'] = gmail_user
msg['To'] = ", ".join(recipients)
msg['Subject'] = subject
msg.attach(MIMEText(text))
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(attach))
msg.attach(part)
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to, msg.as_string())
mailServer.close()
mail("recipient1#email.com, recipient2#email.com",
"Subject",
"Message",
"attchachment")
Any insight would be greatly appreciated.
Best,
Matt
It should be more like
mail(["recipient1#email.com", "recipient2#email.com"],
"Subject",
"Message",
"attchachment")
You already have a array of recipients declared,that too globally,You can use that without passing it as an argument to mail.
I wrote this bit of code to do exactly what you want. If you find a bug let me know (I've tested it and it works):
import email as em
import smtplib as smtp
import os
ENDPOINTS = {KEY: 'value#domain.com'}
class BoxWriter(object):
def __init__(self):
pass
def dispatch(self, files, box_target, additional_targets=None, email_subject=None, body='New figures'):
"""
Send an email to multiple recipients
:param files: list of files to send--requires full path
:param box_target: Relevant entry ENDPOINTS dict
:param additional_targets: other addresses to send the same email
:param email_subject: optional title for email
"""
destination = ENDPOINTS.get(box_target, None)
if destination is None:
raise Exception('Target folder on Box does not exist')
recipients = [destination]
if additional_targets is not None:
recipients.extend(additional_targets)
subject = 'Updating files'
if email_subject is not None:
subject = email_subject
message = em.MIMEMultipart.MIMEMultipart()
message['From'] = 'user#domain.com'
message['To'] = ', '.join(recipients)
message['Date'] = em.Utils.formatdate(localtime=True)
message['Subject'] = subject
message.attach(em.MIMEText.MIMEText(body + '\n' +'Contents: \n{0}'.format('\n'.join(files))))
for f in files:
base = em.MIMEBase.MIMEBase('application', "octet-stream")
base.set_payload(open(f, 'rb').read())
em.Encoders.encode_base64(base)
base.add_header('Content-Disposition', 'attachment; filename={0}'.format(os.path.basename(f)))
message.attach(base)
conn = smtp.SMTP('smtp.gmail.com', 587)
un = 'user#gmail.com'
pw = 'test1234'
conn.starttls()
conn.login(un, pw)
conn.sendmail('user#domain.com', recipients, message.as_string())
conn.close()
I was facing the same issue, I fixed this issue now. Here is my code -
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
import datetime
def sendMail():
message = MIMEMultipart()
message["To"] = "xxxxx#xxxx.com,yyyy#yyyy.com"
message["Cc"] = "zzzzzz#gmail.com,*********#gmail.com"
message["From"] = "xxxxxxxx#gmail.com"
message["Password"] = "***************"
server = 'smtp.gmail.com:587'
try:
now = datetime.datetime.now()
message['Subject'] = "cxxdRL Table status (Super Important Message) - "+str(now)
server = smtplib.SMTP(server)
server.ehlo()
server.starttls()
server.login(message["From"], message["Password"])
server.sendmail(message["From"], message["To"].split(",") + message["Cc"].split(","), message.as_string())
server.quit()
print('Mail sent')
except:
print('Something went wrong...')
sendMail()