Skip to content

Created automatic mail sender script #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions auto_mail_sender/auto_mail_sender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Following code has been written and tested on Python 3.7.
This script sends mail with the given content to the specified recipients.
Example usage: When user needs to send auto-generated reports to multiple recipients.
"""
import win32com.client as win32object

"""
Launching the outlook application.
"""
outlook_object = win32object.Dispatch('outlook.application')


def send_mail_outlook(to_list=None, cc_list=None, bcc_list=None, list_attachment=None, subject=None, content=None):
"""
:param to_list: list of email addresses for "To"
:param cc_list: list of email addresses for "CC"
:param bcc_list: list of email addresses for "BCC"
:param list_attachment: list of email addresses for attachment
:param subject: Subject of the mail
:param content: Content of the mail
:return:
"""
mail = outlook_object.CreateItem(0)
if to_list is not None:
mail.To = to_list
if cc_list is not None:
mail.CC = cc_list
if bcc_list is not None:
mail.BCC = bcc_list
if list_attachment is not None:
for path_docs in list_attachment:
mail.Attachments.Add(path_docs)
if subject is not None:
mail.Subject = subject
if content is not None:
mail.Body = content
if to_list is None and cc_list is None and bcc_list is None:
print("Please provide recipient address...")
else:
if subject is None:
print("Mail will be send without subject..")
if content is None:
print("Mail will be send without any message..")
mail.send
print("Mail has been sent..")


def main():
# replace the mail ID with the ones you need to send mail to
to_list = "sample1@gmail.com;sample2@gmail.com"
send_mail_outlook(to_list=to_list)


if __name__ == '__main__':
main()