[Twisted-Python] SMTP with authentication
Alvin Wang
alvinwang at gmail.com
Sat Nov 4 17:55:45 MST 2006
Thanks!!
That worked great.
minor typo
def sent(r):
print "message sent:", r
A question.
In Phil Mayer's example and Marcin Kasperski's example, it seems like there
is a new tcp/ip connection made for each email. Suppose, I want to send
multiple emails to the same smtp server. How would that work?
Thanks
Alvin
*
*On 11/4/06, Phil Mayers <p.mayers at imperial.ac.uk> wrote:
>
> Alvin Wang wrote:
> > I modified this example
>
> You broke the example.
>
> Try this, hopefully it is clearly what is happening:
>
> import StringIO
>
> from twisted.application import service
>
> application = service.Application("SMTP Client Tutorial")
>
> from twisted.application import internet
> from twisted.python import log
> from twisted.internet import defer, reactor
> from twisted.mail import smtp
>
> mailFrom = "from at example.com"
> mailTo = [" to at example.com",]
> mail = StringIO.StringIO("""Date: Fri, 3 Nov 2006 230:14:39 +0000
> From: from at example.com
> To: to at example.com
> Subject: Tutorate!
>
> Hello, how are you, goodbye.
> """)
>
> whenDone = defer.Deferred()
>
> def send(r):
> print "message sent:", r
>
> whenDone.addCallbacks (sent, log.err)
>
> def done(d):
> from twisted.internet import reactor
> reactor.callLater(1, reactor.stop)
>
> whenDone.addBoth(done)
>
> sender = smtp.ESMTPSenderFactory(
> 'YOURUSERNAME',
> 'YOURPASSWORD',
> mailFrom,
> mailTo,
> mail,
> whenDone,
> )
>
> smtpClientService = internet.TCPClient('YOURSERVER', 25, sender)
> smtpClientService.setServiceParent (application)
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
--
Alvin Wang
Gigachannels
650 248 9416
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20061104/fa077cf4/attachment.html>
More information about the Twisted-Python
mailing list