Re: Sending email



On Aug 28, 2:37 am, Fencer <no.i.d...@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
Hello, I'm using Python version 2.6.2 and I discovered it has built-in
libraries for sending email (imports smtplib and email). On the web I
discovered how to send mail through smtp.gmail.com:

mail_server = smtplib.SMTP()

mail_server.connect('smtp.gmail.com')
mail_server.ehlo()
mail_server.starttls()
mail_server.ehlo()
mail_server.login('username', 'password')

msg = MIMEText('Some message text')
msg['Subject'] = 'Some subject'
msg['From'] = 'Mr Underhill'
msg['To'] = 'someemailaddress'

me = 'myemailaddress'
mail_server.sendmail(me, ['someemailaddress'], msg.as_string())

That seems to work just fine but for the messages I will be sending I
don't want to use my private GMail account.
We have an SMTP server at work, and I checked its settings in the
Thunderbird mail client and it's using SSL over port 465, so a bit
different from how GMail's SMTP server is configured in Thunderbird.

I altered my code slightly to account for this:
mail_server = smtplib.SMTP_SSL()
mail_server.connect('mysmtpserver.at.work', 465)

Everything I left untouched. However, it doesn't work:
Traceback (most recent call last):
   File "C:\Users\fencer\workspace\Send Email\src\send_email.py", line
16, in <module>
     mail_server.ehlo()
   File "C:\Python26\lib\smtplib.py", line 382, in ehlo
     self.putcmd(self.ehlo_msg, name or self.local_hostname)
   File "C:\Python26\lib\smtplib.py", line 318, in putcmd
     self.send(str)
   File "C:\Python26\lib\smtplib.py", line 310, in send
     raise SMTPServerDisconnected('please run connect() first')
smtplib.SMTPServerDisconnected: please run connect() first

As you can see, I'm on Windows Vista.

What do I need to change in my code to fix this problem? Thunderbird
manages to do it! :) Ideally, I would like send an email that the
recipient can't reply to, but if doesn't work, it's fine too. I want to
use this to send automated emails to students with account information
for a course.

- Fencer

The docs say:

---
class smtplib.SMTP_SSL([host[, port[, local_hostname[, keyfile[,
certfile[, timeout]]]]]])

A SMTP_SSL instance behaves exactly the same as instances of SMTP.
SMTP_SSL should be used for situations where SSL is required from the
beginning of the connection and using starttls() is not appropriate.
---

So try getting ride of these two lines:

mail_server.starttls()
mail_server.ehlo()

There's also some info on google about a bug in this regard, so check
to see when you installed python 2.6.2.
.



Relevant Pages

  • Sending email
    ... I'm using Python version 2.6.2 and I discovered it has built-in libraries for sending email. ... That seems to work just fine but for the messages I will be sending I don't want to use my private GMail account. ... We have an SMTP server at work, and I checked its settings in the Thunderbird mail client and it's using SSL over port 465, so a bit different from how GMail's SMTP server is configured in Thunderbird. ...
    (comp.lang.python)
  • Re: Must have softwares for Treo 650
    ... >>> What problems are you having sending email? ... >>> be able to at least use Sprint's SMTP server. ... > setup an email account, you usually provide only the login information ... > logged into your home ISP, and sending mail through their SMTP server). ...
    (comp.sys.palmtops.pilot)
  • Re: Must have softwares for Treo 650
    ... >>> What problems are you having sending email? ... >>> be able to at least use Sprint's SMTP server. ... > setup an email account, you usually provide only the login information ... > logged into your home ISP, and sending mail through their SMTP server). ...
    (comp.sys.palmtops.pilot)
  • Outllook Express account dialog when sending email.
    ... When sending email, via Outlook Express, on XP Home Ed., ... with each message we get a dialog that asks for account ... has no permenant effect. ... remember the outgoing mail account name/passwd. ...
    (microsoft.public.windowsxp.security_admin)
  • eror sending message with mime/smtp (flush). message size?
    ... I get when sending email to a particular SMTP server. ... 14:35:03 MIME-Version: 1.0 ... 14:35:03 Content-Type: text/plain ...
    (comp.lang.tcl)