Re: smtplib starttls gmail example

Discussion in 'Python' started by Jean-Paul Calderone, Jan 23, 2007.

  1. On Tue, 23 Jan 2007 17:25:24 GMT, py <> wrote:
    >from smtplib import SMTP
    >from socket import sslerror #if desired
    >server = SMTP('smtp.gmail.com')
    >server.set_debuglevel(0) # or 1 for verbosity
    >server.ehlo('')
    >server.starttls()
    >server.ehlo('') # say hello again
    >server.login('', 'yourpassword')
    ># i have a suspicion that smptlib does not add the required newline dot newline so i do it myself
    >server.sendmail('', '', message_text + '\n.\n')
    ># next line generates the ignorable socket.sslerror
    >server.quit()
    >


    Or with Twisted:

    from twisted.internet.ssl import ClientContextFactory
    from twisted.internet.defer import Deferred
    from twisted.mail.smtp import ESMTPSenderFactory
    from twisted.internet import reactor

    contextFactory = ClientContextFactory()
    result = Deferred()
    factory = ESMTPSenderFactory('',
    'your password',
    '',
    '',
    messageText,
    contextFactory=contextFactory)
    reactor.connectTCP('smtp.gmail.com', 25, factory)
    result.addCallback(lambda ign: reactor.stop())
    reactor.run()

    Jean-Paul
     
    Jean-Paul Calderone, Jan 23, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Williams

    smtplib STARTTLS problems

    Tim Williams, Apr 12, 2005, in forum: Python
    Replies:
    0
    Views:
    456
    Tim Williams
    Apr 12, 2005
  2. py
    Replies:
    0
    Views:
    365
  3. Tim Williams
    Replies:
    0
    Views:
    487
    Tim Williams
    Jan 24, 2007
  4. DJ Fadereu

    Gmail Error using smtplib

    DJ Fadereu, Jul 20, 2007, in forum: Python
    Replies:
    1
    Views:
    3,574
    supercooper
    Jul 20, 2007
  5. Evan
    Replies:
    3
    Views:
    519
Loading...

Share This Page