Email Via Python so i know when i get an error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shaggy89
    New Member
    • Dec 2012
    • 1

    Email Via Python so i know when i get an error

    Hi all,
    I would like to send an email from my Gmail account using python so when i have an error ill receive an auto email. At current the program handles the errors internally and keeps trying to do its task. That part is fine but when it hits an error I would like to receive an email. So i did some googling and found this nice script

    Code:
    import smtplib
    fromaddr = 'my email'
    toaddrs = 'to my email'
    msg = 'Test Email message'
    #provide gmail user name and password
    username = 'username'
    password = 'password'
    # functions to send an email
    server = smtplib.SMTP('smtp.googlemail.com:465')
    server.ehlo()
    server.starttls()
    server.ehlo()
    server.login(username,password)
    server.sendmail(fromaddr, toaddrs, msg)
    server.quit()
    but i get an error

    Code:
    Traceback (most recent call last):
      File "C:\email.py", line 1, in <module>
        import smtplib
      File "C:\Python27\lib\smtplib.py", line 46, in <module>
        import email.utils
      File "C:\email.py", line 11, in <module>
        server = smtplib.SMTP('smtp.googlemail.com:465')
    AttributeError: 'module' object has no attribute 'SMTP'
    So I have checked the Lib folder and Smtplib.py is there and so is the email folder and the utils.py file.

    Can anyone help ?

    Cheers Shane

    P.s using winblows
    Last edited by Rabbit; Dec 6 '12, 09:08 PM. Reason: Please use code tags when posting code.
  • roberttonafelix
    New Member
    • Oct 2012
    • 16

    #2
    hi,

    It was quite difficult to connect the gmail server for send and receiving the mails via python instead if you have an outlook account it is possible send email using python...

    if you want the gmail account mail's to the outlook email address follow the below setting...
    login to your gmail account and select the settings and in the that select forwarding and pop/imap and in that give the outlook email address and use the below python script for sending outlook emails....
    Code:
    import mailer
    import time
    import datetime
    from datetime import datetime
    message = mailer.Message()
    message.From = "example@example.com"
    message.To = "example@example.com"
    message.Subject = "test"
    message.Body = "This is automated mail please don't reply to this mail."
    mailer = mailer.Mailer('use the server address.com')
    mailer.send(message)
    print "sent"
    for the mailer package download go to the below address..
    Last edited by Rabbit; Dec 7 '12, 06:09 AM. Reason: Please use code tags when posting code.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      Also, Python has the SMPT module. Doug Hellmann's page is one place for more info.

      Comment

      Working...