Python: Create a user and send email with account details to the user
Question: Here is a script I have written which will create a new user account. I am
trying to get help in adding a bit more to it.

I want to have it also send an email to the new user that is created. Ideally,
the program will ask the user creating the new account, what their email is,
and then it will use the user and password variables and send an email to that
new user so they will know how to log in. What would be the best way to do
this, thanks for any advice.

    
    
    #! /usr/bin/python
    
    import commands, os, string
    import sys
    import fileinput
    
    
    def print_menu():       ## Your menu design here
        print 20 * "-" , "Perform Below Steps to Create a New TSM Account." , 20 * "-"
    print "1. Create User Account"
    print 67 * "-"
    
    loop=True      
    
    while loop:          ## While loop which will keep going until loop = False
        print_menu()    ## Displays menu
        choice = input("Enter your choice [1-5]: ")
    
        if choice==1:
            user = raw_input("Enter the Username to be created: " )
            password = raw_input( "Enter the password for the user: "  )
            SRnumber = raw_input( "Enter the Service Request Number: ")
    
            user = user + " "
    
            output = os.system('create user' + user)
            output = os.system('set password' + password)
    


Answer: You can easily send mails with gmail and smtplib (you maybe need to install it
first). This way you can send any message you want.

    
    
    import smtplib
    
    toaddrs = raw_input('what is your e mail?')
    fromaddr = 'youremail@email.com'
    
    msg = 'the message you want to send'
    server.starttls()
    server.login(fromaddr, "your gmail password")
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.set_debuglevel(1)
    server.sendmail(fromaddr, toaddrs, msg)
    server.quit()
    

You will have to allow less secure apps in your gmail settings.

