-2

My program takes entered data and creates several batch / docx files. Is there a way to take my entered data and create a file that, when clicked on, will automatically send an e-mail to a specified e-mail address from a specific Gmail account? or better yet, open chrome and prepare the e-mail to be sent text and all?

The Gmail account I would like to use is delegated (controlled by various users), and the e-mail would have to come from this account, and not my personal Gmail account that I'm signed in to as well.

edit: it doesn't have to open chrome. can be anything. as long as i can make changes before i hit send.

t0m3k
  • 307
  • 1
  • 11

1 Answers1

0

Create a batch file that will run a python file that you create For example a batch file with the following line

python -m your_module.your_python_file

create a python file called your_python_file.py with the following code

import logging
from logging.handlers import SMTPHandler

if(__name__ == "__main__"):
    logger = logging.getLogger()

    server_email_address = 'your_gmail_address'
    server_account_password = 'your_gmail_password'
    destination_email_address = 'destination_email_address'

    emailh = SMTPHandler(('smtp.gmail.com', 587)
                     ,server_email_address
                     ,destination_email_address
                     ,'your subject'
                     ,(server_email_address, server_account_password)
                     , secure=())

    emailh.setLevel(logging.WARNING)
    logger.addHandler(emailh)

    # input the email message to send
    msg = input('enter message \n')

     # send the email
    logger.warning(msg)

when you click on the batch file, it should open a console window and run the python code. It should prompt you for an input - the email message to be sent - then it will send the email

Arran Duff
  • 716
  • 1
  • 5
  • 16
  • wont work if there is no python on the target system and in its path – Patrick Artner Feb 09 '19 at 19:42
  • Considering that it's a python question, I assume that he wants a python solution – Arran Duff Feb 09 '19 at 19:44
  • Pretty cool. However, the account has 2FA on it so this didn't work for me. Thank you for sharing though. – t0m3k Feb 09 '19 at 19:48
  • also, yeah, some of my coworkers use my software and they don't have python installed. i'd have to figure out how to do this on a machine without python. -_- – t0m3k Feb 09 '19 at 19:48
  • https://stackoverflow.com/questions/26736062/sending-email-fails-when-two-factor-authentication-is-on-for-gmail Shows how to get around 2FA in gmail. I can't help you if your colleagues don't have python. The question is tagged as a python question. You should probably move it... – Arran Duff Feb 09 '19 at 20:08