How to send an email on a private telekom smtp? - python

I want send an email automatically, but i get this error message:
"Connection unexpectedly closed: [Errno 104] Connection reset by peer"
I tried a few smtp server methode, but it can't work.
My code is here:
fromaddr = "test#gmail.com"
toaddr = "test2#gmail.com"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "test"
body = "Test"
msg.attach(MIMEText(body, 'plain'))
#server = smtplib.SMTP('smtp.example.com', 25)
server = smtplib.SMTP_SSL('mail.dt-one.com', 443)
#server.connect("mail.t-online.hu",2525)
server.ehlo()
server.starttls()
server.ehlo()
server.login('myuser','mypassword')
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()

Related

errors when creating a python mailing client [duplicate]

Using python I want to send email from my app but it shows the error
SMTP AUTH extension not supported by server
Code for the program,
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
fromaddr = "test1#example.com"
toaddr = "test2#example.com"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Test Mail"
body = "Test mail from python"
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.example.com', 25)
server.ehlo()
server.starttls()
server.ehlo()
server.login(fromaddr, "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
Telnet Output:
ehlo test1.example.com
250-hidden
250-HELP
250-SIZE 104857600
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-STARTTLS
250 OK
I need to authenticate and send mail from app.
a connection is required before login and sendemail.
server = smtplib.SMTP('smtp.example.com', 25)
server.connect("smtp.example.com",465)
server.ehlo()
server.starttls()
server.ehlo()
server.login(fromaddr, "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
There is no need to call smtp.connect() and smtp.ehlo(), because they are called automatically by SMTP() and smtp.starttls(). The issue is solved simply setting port to 587 instead of 28.
For client use, if you don’t have any special requirements for your security policy, it is highly recommended that you use the create_default_context() function to create your SSL context. It will load the system’s trusted CA certificates, enable certificate validation and hostname checking, and try to choose reasonably secure protocol and cipher settings.
In general, you will want to use the email package’s features to construct an email message, which you can then send via send_message().
import smtplib, ssl
from email.message import EmailMessage
msg = EmailMessage()
msg.set_content("The body of the email is here")
msg["Subject"] = "An Email Alert"
msg["From"] = "me#example.com"
msg["To"] = "you#example.com"
context=ssl.create_default_context()
with smtplib.SMTP("smtp.example.com", port=587) as smtp:
smtp.starttls(context=context)
smtp.login(msg["From"], "p#55w0rd")
smtp.send_message(msg)
It is probably just the server I was using, but was getting the same error as the OP even after implementing the accepted solution. Turned out the server did not want a login, so after deleting the line server.login(fromaddr, "password"), the error went away and it worked.
you need to 'starttls' before login.
import smtplib
s = smtplib.SMTP('smtplib.gmail.com',587)
s.ehlo()
s.starttls()
s.login('frmaddr','password')
try:
s.sendmail('fromaddr','toaddr','message')
except:
print (failed)
The first tap is enable your gmail account to send emails by another applications, allow in this section:
https://myaccount.google.com/lesssecureapps
Then, you should can to send an email
import json
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
msg = MIMEMultipart()
message = "This is an email"
password = "yourpasswordemailsender"
msg['From'] = "emailsender#gmail.com"
msg['To'] = "emailsended#gmail.com"
msg['Subject'] = "Title of email"
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(msg['From'], password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()

Unable to send mail in python on Outlook with the smtplib

I try to send email via an Outlook account, but I am unable to. I successfully did sent email with Gmail, but I am unable to with Outlook.
I tried tried to change the host and port between
SMTP.office365.com Port : 587
and ..
smtp-mail.outlook.com Port : 587
not working. Same error.
Gmail sending :
def sendmail(from_email, password, to_email, subject, message):
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_email
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465) #Info pour send depuis une addresse courriel
server.ehlo()
server.login(from_email, password)
server.sendmail(from_email, to_email, msg.as_string())
server.close
return True
except Exception as e:
print ("Something went wrong :", str(e))
return False
sendmail('email#gmail.com', 'password', 'email1#gmail.com', 'subject', 'this is message body ; so hot ! ')
Outlook "sending" :
def sendmail(from_email, password, to_email, subject, message):
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_email
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
try:
server = smtplib.SMTP_SSL('SMTP.office365.com', 587) #Info pour send depuis une addresse courriel
server.ehlo()
server.login(from_email, password)
server.sendmail(from_email, to_email, msg.as_string())
server.close
return True
except Exception as e:
print ("Something went wrong :", str(e))
return False
sendmail('email#outlook.com', 'password', 'email1#gmail.com', 'subject', 'this is message body ; so hot ! ')
Excepted : Mail sending on email1#gmail.com
Error : Something went wrong : [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)
When I delete _SSL, an error occure;
Something went wrong : SMTP AUTH extension not supported by server

SMTP AUTH extension not supported by server

Using python I want to send email from my app but it shows the error
SMTP AUTH extension not supported by server
Code for the program,
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
fromaddr = "test1#example.com"
toaddr = "test2#example.com"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Test Mail"
body = "Test mail from python"
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.example.com', 25)
server.ehlo()
server.starttls()
server.ehlo()
server.login(fromaddr, "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
Telnet Output:
ehlo test1.example.com
250-hidden
250-HELP
250-SIZE 104857600
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-STARTTLS
250 OK
I need to authenticate and send mail from app.
a connection is required before login and sendemail.
server = smtplib.SMTP('smtp.example.com', 25)
server.connect("smtp.example.com",465)
server.ehlo()
server.starttls()
server.ehlo()
server.login(fromaddr, "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
There is no need to call smtp.connect() and smtp.ehlo(), because they are called automatically by SMTP() and smtp.starttls(). The issue is solved simply setting port to 587 instead of 28.
For client use, if you don’t have any special requirements for your security policy, it is highly recommended that you use the create_default_context() function to create your SSL context. It will load the system’s trusted CA certificates, enable certificate validation and hostname checking, and try to choose reasonably secure protocol and cipher settings.
In general, you will want to use the email package’s features to construct an email message, which you can then send via send_message().
import smtplib, ssl
from email.message import EmailMessage
msg = EmailMessage()
msg.set_content("The body of the email is here")
msg["Subject"] = "An Email Alert"
msg["From"] = "me#example.com"
msg["To"] = "you#example.com"
context=ssl.create_default_context()
with smtplib.SMTP("smtp.example.com", port=587) as smtp:
smtp.starttls(context=context)
smtp.login(msg["From"], "p#55w0rd")
smtp.send_message(msg)
It is probably just the server I was using, but was getting the same error as the OP even after implementing the accepted solution. Turned out the server did not want a login, so after deleting the line server.login(fromaddr, "password"), the error went away and it worked.
you need to 'starttls' before login.
import smtplib
s = smtplib.SMTP('smtplib.gmail.com',587)
s.ehlo()
s.starttls()
s.login('frmaddr','password')
try:
s.sendmail('fromaddr','toaddr','message')
except:
print (failed)
The first tap is enable your gmail account to send emails by another applications, allow in this section:
https://myaccount.google.com/lesssecureapps
Then, you should can to send an email
import json
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
msg = MIMEMultipart()
message = "This is an email"
password = "yourpasswordemailsender"
msg['From'] = "emailsender#gmail.com"
msg['To'] = "emailsended#gmail.com"
msg['Subject'] = "Title of email"
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(msg['From'], password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()

Gmail SMTP rejecting my login

smtplib.SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbvuQ\n5.7.14 hjav3RshZ9XqmApuN6mVTPJ_3AZUJEkiniSxdgdVMrgEpKpUtHi8_oCjzuOA9pkhGMyTrs\n5.7.14 fuSX9EuvWudU00Q1KXZgY4rZ1I5ZEEDOqvVMl7bOQitwyb_sYdgPA3tJC7_xpUN1zDC6Ib\n5.7.14 MjA2mM_oMdCOeCpodh-13LwLFlyzmZALwg2uu522OxG0NH74B2hafBfT2F1XK0lXCz1hce\n5.7.14 3yugD0g> Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 bw2sm40059670pad.46 - gsmtp')
I am getting the above error from the below script. And yes I have verified that I am using my correct credentials. All I want to do is send an email from a script! Has anyone run into this issue before?
import smtplib
FROMADDR = "my.real.address#gmail.com"
LOGIN = FROMADDR
PASSWORD = "my.real.password"
TOADDRS = ["my.real.address#gmail.com"]
SUBJECT = "Test"
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
% (FROMADDR, ", ".join(TOADDRS), SUBJECT) )
msg += "some text\r\n"
server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(LOGIN, PASSWORD)
server.sendmail(FROMADDR, TOADDRS, msg)
server.quit()
You have to enable 'Access for less secure apps' option in your Google account security section.
Try changing your code to:
server.ehlo()
server.starttls()
server.ehlo() # you are missing elho to establish communication with server
server.login(username, password)
# Full script
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from_address = 'you#gmail.com'
to_address = 'you80#gmail.com'
text = 'test message sent from Python'
username = '****'
password = '****'
msg = MIMEMultipart()
msg['From'] = from_address
msg['To'] = to_address
msg['Subject'] = 'Foo'
msg.attach(MIMEText(text))
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, password)
server.sendmail(from_address, to_address, msg.as_string())
server.quit()
If you have not logged in using your browser since the error messages, you should also try that as if you had a number of unsuccessful logins you will have to enter a captcha,
The solution to this ended up being changing my gmail password. I never did figure out which special characters were throwing everything off, but I just generated a new password and had no problems with this after that.

Issue sending email with python?

I'm trying to make an email script in python. Here's what I have (from pythonlibrary.org):
#! /usr/bin/env python
import smtplib
import string
SUBJECT = "An email!"
TO = "me#icloud.com"
FROM = "me#gmail.com"
text = "This text is the contents of an email!"
BODY = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT ,
"",
text
), "\r\n")
server = smtplib.SMTP('smtp.gmail.com')
server.login('me#gmail.com', 'mypassword') # Not very secure, I know, but this email is dedicated to this script
server.sendmail(FROM, [TO], BODY)
server.quit()
I get smtplib.SMTPException: SMTP AUTH extension not supported by server. Is this is so, then why does smtp.gmail.com respond at all? Is this a problem with Gmail, or my script, or something else?
Error message:
Traceback (most recent call last):
File "/Users/student/Desktop/mail.py", line 18, in <module>
server.login('*******#gmail.com', '**************')
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 552, in login
smtplib.SMTPException: SMTP AUTH extension not supported by server.
You need to contact the gmail mail server on the submission port (587), not the default 25:
server = smtplib.SMTP('smtp.gmail.com', 587)
You also need to use server.starttls() before logging in (so that your password is not sent in the clear!). This is from a script I have and it works for me:
server = smtplib.SMTP()
server.connect("smtp.gmail.com", "submission")
server.starttls()
server.ehlo()
server.login(user, password)
Here's how to send e-mail using gmail in Python:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from email.header import Header
from email.mime.text import MIMEText
from getpass import getpass
from smtplib import SMTP_SSL
login, password = 'user#gmail.com', getpass('Gmail password:')
# create message
msg = MIMEText('message body…', _charset='utf-8')
msg['Subject'] = Header('subject…', 'utf-8')
msg['From'] = login
msg['To'] = login
# send it via gmail
s = SMTP_SSL('smtp.gmail.com', 465, timeout=10)
s.set_debuglevel(1)
try:
s.login(login, password)
s.sendmail(msg['From'], msg['To'], msg.as_string())
finally:
s.quit()
I found I had to do an ehlo() and a starttls() before sending mail via gmail:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(SERVER_EMAIL,EMAIL_HOST_PASSWORD)
It shouldn't make a difference with the login, but I use a MIMEMultipart from email.mime.multipart for the body, with something like:
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = mFrom
msg['To'] = mTo
if textBody:
part1 = MIMEText(textBody, 'plain')
msg.attach(part1)
if htmlBody:
part2 = MIMEText(htmlBody, 'html')
msg.attach(part2)
BODY = msg.as_string()

Categories

Resources