Sending an email, via python, from one outlook account to another

只谈情不闲聊 提交于 2019-12-08 11:46:27

问题


I'm writing a program to help the school's Biology Department and it involves sending an email. I've gathered all of the variables I need for the content of the message, it's just the actual sending of the email that's causing some issues.

I've looked around and realized that I was using code that sent to gmail, whereas the servers at school use Outlook 2010. Once I remembered that, I looked around for some python code that sent emails, but so far nothing has worked.

It all seems very complicated for just sending an email, but I need some help as to were to go from here.

gsal.org.uk is our school's web server address, which is an outlook server.

The current error that I am receiving is smtplib.SMTPException: STARTTLS extension not supported by server., but I keep receiving various errors with everything I try.

This is the code:

        fromaddr = "test@gsal.org.uk"
        toaddrs = "technicians@gsal.org.uk"
        msg = "\r\n".join([
            "From: user",
            "To: user",
            "Subject: Practical Request",
            "",
            "Test"
            ])

        server = smtplib.SMTP_SSL('smtp.gmail.com:465')
        server.ehlo()
        server.starttls()
        # server.login(username,password)
        server.sendmail(fromaddr, toaddrs, msg)
        server.quit()
        messagebox.showinfo("Success!", "Your request has been sent successfully.")

All I want to do is send an email from an email account (specified within the program) to an email account that will soon be set up at school called technicians@gsal.org.uk. Any help appreciated.

EDIT

Thought I'd add the fact that if I remove the starttls() line, I get this: smtplib.SMTPSenderRefused: (530, b'5.5.1 Authentication Required. Learn more at\n5.5.1 https://support.google.com/mail/answer/14257 hw1sm42144009wjb.6 - gsmtp', 'test@gsal.org.uk')

I've read that link, but it seems to be talking about gmail? I want to use outlook? I understand that I need to do authentication, but how?


回答1:


In order to fight spam and protect resources, a normally configured SMTP server provides its services only to its owner (e.g. a company, organization or registered customers). Your school server probably accepts mail only if it is:

  • addressed to the school's own domain, or
  • coming from an authenticated person (e.g. a student, teacher), or
  • coming from a host with IP address belonging to the school's LAN (when allowed by the admin)

Further, a SMTP server communicates with other servers on TCP port 25 and with users submitting new mail (which is your case) on port 465 or 587. (Port 25 was used in the past for all mail, this is now deprecated)

Communication on port 465 is always encrypted (TLS). Communication on port 587 starts in plaintext, but with the STARTTLS command, the encryption is turned on. A successfull STARTTLS is usually required to allow authentication (login).


Why your progam does not work?

  • You are trying to start TLS on an TLS connection. It has been started. Either don't STARTTLS or change the port to 587.
  • You are using gmail's server to send a message not addressed to gmail. In this case you must login with a name and a password as a registered gmail user.

What should help? Contact the local admin for details about using the school's own server.



来源:https://stackoverflow.com/questions/33983076/sending-an-email-via-python-from-one-outlook-account-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!