[Tutor] need to automate connection
Liam Clarke
ml.cyresse at gmail.com
Tue Apr 25 08:59:29 CEST 2006
Hi Payal,
I see you're connecting to an smtp server Any particular reason yoou
can't use smtplib?
http://www.python.org/doc/current/lib/module-smtplib.html
Here's a sample script using smtplib to send an email -
import smtplib
ip = "127.0.0.1"
txt = "This is an email message"
c = smtplib.SMTP(ip)
c.sendmail("sender at server.net", "recipient at remote_server.net", txt)
c.close()
Although it's better to use an email.Message object for this -
http://www.python.org/doc/current/lib/module-email.Message.html
Here's the same script with an email.Message
import smtplib
import email.Message as Mg
ip = "127.0.0.1"
msg = Mg.Message()
msg["To"] = "recipient at remote_server.net
msg["From"] = "sender at server.net"
msg["Subject"] = "Test message"
msg["Reply-To"] = "alternate_address at server.net"
txt = "This is an email message"
msg.set_payload(txt)
c = smtplib.SMTP(ip)
c.sendmail("sender at server.net", "recipient at remote_server.net", msg.as_string())
c.close()
Regards,
Liam Clarke
On 4/25/06, Payal Rathod <payal-python at scriptkitchen.com> wrote:
> Hi,
> I need to automate connection to a IP like this. The IP (or domain name)
> is taken from command line or from user (whichever is easier for me to
> code). It should emulate,
>
> telnet 127.0.0.1 25
>
> mail from: <test at test.com>
> 250 ok
> rcpt to: <support at example.com>
> 250 ok
> quit
>
> Can Python do this for me? How do I start?
>
> With warm regards,
> -Payal
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list