I modified this example<br><a href="http://twistedmatrix.com/projects/mail/documentation/tutorial/smtpclient/smtpclient-7.tac">http://twistedmatrix.com/projects/mail/documentation/tutorial/smtpclient/smtpclient-7.tac</a><br>
<br>I am still not completely clear on what is happening <br><br>Thanks for the help<br>Alvin<br><br><br>import StringIO<br><br>from twisted.application import service<br><br>application = service.Application(&quot;SMTP Client Tutorial&quot;)
<br><br>from twisted.application import internet<br>from twisted.internet import protocol<br>from twisted.mail import smtp<br>from twisted.mail.imap4 import CramMD5ClientAuthenticator<br><br>class SMTPTutorialClient(smtp.ESMTPClient
):<br>&nbsp;&nbsp;&nbsp; mailFrom = &quot;<a href="mailto:from@sender.com">from@sender.com</a>&quot;<br>&nbsp;&nbsp;&nbsp; mailTo = &quot;<a href="mailto:to@dest.com">to@dest.com</a>&quot;<br>&nbsp;&nbsp;&nbsp; mailData = '''\<br>Date: Fri, 6 Feb 2006 10:14:39 -0800
<br>From: <a href="mailto:from@sender.com">from@sender.com</a><br>To: <a href="mailto:to@dest.com">to@dest.com</a><br>Subject: Tutorate!<br><br>Hello, how are you, goodbye.<br>'''<br><br>&nbsp;&nbsp;&nbsp; def getMailFrom(self):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; result = 
self.mailFrom<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.mailFrom = None<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return result<br><br>&nbsp;&nbsp;&nbsp; def getMailTo(self):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return [self.mailTo]<br><br>&nbsp;&nbsp;&nbsp; def getMailData(self):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return StringIO.StringIO(self.mailData)<br>
<br>&nbsp;&nbsp;&nbsp; def sentMail(self, code, resp, numOk, addresses, log):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print 'Sent', numOk, 'messages'<br><br>class SMTPClientFactory(protocol.ClientFactory):<br>&nbsp;&nbsp;&nbsp; protocol = SMTPTutorialClient<br><br>&nbsp;&nbsp;&nbsp; def buildProtocol(self, addr):
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return self.protocol(secret=None, identity='<a href="http://sender.com">sender.com</a>')<br><br>class SMTPClientFactory(protocol.ClientFactory):<br>&nbsp;&nbsp;&nbsp; protocol = SMTPTutorialClient<br>&nbsp;&nbsp;&nbsp; #def __init__(self, *a, **kw):
<br>&nbsp;&nbsp;&nbsp; #&nbsp;&nbsp;&nbsp; self.a, <a href="http://self.kw">self.kw</a> = a, kw<br><br>&nbsp;&nbsp;&nbsp; def buildProtocol(self, addr):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p = smtp.ESMTPClient('smtp_pw')<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p.factory = self<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p.requireAuthentication = True<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p.authenticators = {'CRAM-MD5': CramMD5ClientAuthenticator('smtp_user')}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return p<br><br>smtpClientFactory = SMTPClientFactory()<br><br>smtpClientService = internet.TCPClient('<a href="http://smtp.1and1.com">
smtp.1and1.com</a>', 25, smtpClientFactory)<br>smtpClientService.setServiceParent(application)<br><br><br><div><span class="gmail_quote">On 11/3/06, <b class="gmail_sendername">Jean-Paul Calderone</b> &lt;<a href="mailto:exarkun@divmod.com">
exarkun@divmod.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Fri, 3 Nov 2006 16:17:15 -0800, Alvin Wang &lt;<a href="mailto:alvinwang@gmail.com">
alvinwang@gmail.com</a>&gt; wrote:<br>&gt;Hi,<br>&gt;<br>&gt;I am new to twisted but google and the Oreilly book have failed me.&nbsp;&nbsp;I am<br>&gt;trying to create a client to send to a smtp server.&nbsp;&nbsp;All the examples that I<br>
&gt;have found only work if your&nbsp;&nbsp;SMTP server does not require authentication.<br>&gt;<br>&gt;I am guessing that I need to use<br>&gt;<a href="http://twistedmatrix.com/documents/current/api/twisted.mail.smtp.ESMTPSenderFactory.html">
http://twistedmatrix.com/documents/current/api/twisted.mail.smtp.ESMTPSenderFactory.html</a><br>&gt;<br>&gt;<br>&gt;Unfortunately, I can find no examples that use it.<br>&gt;<br>&gt;I did find something from 2004<br>&gt;<a href="http://twistedmatrix.com/pipermail/twisted-python/2004-April/007433.html">
http://twistedmatrix.com/pipermail/twisted-python/2004-April/007433.html</a><br><br>This should still work.<br><br>&gt;<br>&gt;That is prior to the commit for ESMTPSenderFactory<br>&gt;<a href="http://twistedmatrix.com/pipermail/twisted-commits/2004-July/011608.html">
http://twistedmatrix.com/pipermail/twisted-commits/2004-July/011608.html</a><br><br>This changed ESMTPSenderFactory, but authentication was supported before<br>this commit.&nbsp;&nbsp;Give the code at the previous URL a try and post again if
<br>you run into problems.<br><br>Jean-Paul<br><br>_______________________________________________<br>Twisted-Python mailing list<br><a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br></blockquote></div><br><br>