Code is provided below:
import smtplib
s=smtplib.SMTP('127.0.0.1',587)
s.starttls()
s.login("EMAIL_ADDRESS#gmail.com","PASSWORD")
messsage="congrats"
s.sendmail('EMAIL_ADDRESS#gmail.com','RECIPIENT_ADDRESS#gmail.com',message)
s.quit()
Error:
SMTPAuthenticationError:
(535, b'5.7.8 Username and Password not accepted.
The SMTP server should be smtp.gmail.com, not 127.0.0.1. 127.0.0.1 refers to localhost or the current server you are running on. So unless you happen to be running on Gmail's SMTP server, this will not work as you currently have it. Of course, you must also use a correct email/password combination.
Related
This is my code for the gmail smtp server.
def verify_email(self, user_email, sending_email, password):
port = 465
self.sending_mail = sending_email
self.password = password
if (re.fullmatch(regex, user_email)):
self.user_email = user_email
else:
raise Exception("Sorry, your email is invalid.")
self.email_msg = f"""
Subject: Verify Email
Is this you, {self.username}?
Please enter the code below to verify:
[{verify_code}]
From,
{self.sending_mail}
"""
context = ssl.create_default_context()
try:
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
server.login(self.sending_mail, self.password)
server.sendmail(self.sending_mail, self.user_email, self.email_msg)
except:
print("An error has happened. Please check the spelling of your email, "
"or try again. 🙂")
How can I use the 10 minute mail SMTP server?
I used Google but I didn't understand any of it.
When I used Gmail I got this error:
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials g15-20020a056a0023cf00b004e17e11cb17sm9404507pfc.111 - gsmtp')
So I decided to use 10minute mail. In my gmail account, I can't change the settings to allow Less Secure Apps.
Gmail recently announced that they wouldn't allow unsecure connections like SMTP on May 30th of 2022.
Using SMTP through gmail requires that you enable the setting "Allow less secure apps" in account settings to be able to connect.
I'd try something like Yahoo, or Outlook, or another email provider that allows SMTP. Look up their server information, and what security privilege's you need to enable for the connection to happen for which provider you choose.
I'm not familiar with 10 Minute Mail, but just wanted to give that insight to Gmail's SMTP server. Hopefully someone else can help you set it up through 10 minute mail.
I have been using the smtplib module in python to send text messages from a gmail account and my requests to connect to the server recently started being denied. My code isn't anything special:
import smtplib
server = smtplib.SMTP( "smtp.gmail.com", 587 )
server.starttls()
server.login( '<gmail_address>', '<gmail_password>’ )
server.sendmail( '<from>', '<number>#mms.att.net', '<msg>’ )
An error is thrown at the 4th line
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534,
and gmail notifies me that they have blocked a sign-in attempt from an app, because it didn't meet modern security requirements.
I'm hoping to find a work around that allows me to continue sending SMS messages using the smtplib module.
Google explain that you can lower your security settings but they don't rcommend it, and give precious little in the way of advice apart from that.
I want to try hiding my main IP and send email using Hotmail SMTP via Python SMTP Lib. I'm using the following code to send email but its sent from my IP (Originally it sends from Hotmail SMTP but it still shows my IP in the header if can see).
import smtplib
SMTP = "smtp.live.com"
s = smtplib.SMTP(SMTP,587)
s.ehlo()
s.starttls()
s.ehlo()
s.login("username#hotmail.com", "Password")
s.sendmail("username#hotmail.com", "recipient#hotmail.com","Hello World")
Let me know if there's any thing possible from which I can hide my IP and use the proxy IP to send the email. Furthermore, I think playing with socket/socks library might do the trick but still unsure.
Thank you very much.
I have the following line of code using imaplib
M = imaplib.IMAP4('smtp.gmail.com', 587)
I get the following error from imaplib:
abort: unexpected response: '220 mx.google.com ESMTP o13sm12303588vde.21'
However from reading elsewhere, it seems that that response is the correct response demonstrating that the connection was made to the server successfully at that port.
Why is imaplib giving this error?
You are connecting to the wrong port. 587 is authenticated SMTP, not IMAP; the IMAP designated port number is 143 (or 993 for IMAPS).
I realized I needed to do IMAP4_SSL() - has to be SSL for IMAP and for using IMAP I need the IMAP server for gmail which is imap.googlemail.com. I ultimately got it work without specifying a port. So, final code is:
M = imaplib.IMAP4_SSL('imap.googlemail.com')
as indicated by the title I am having trouble sending an email via my gmail account through a python application.I have searched online for a solution but nothing seems to solve it and I thought I might ask here.
My code is the following:
FROMADDR = "myemail#gmail.com"
LOGIN = FROMADDR
PASSWORD = "mypass"
TOADDRS = "varis81#hotmail.com"
msg = "Test message"
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()
print "E-mail succesfully sent"
I get the message:
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I tried different ports but it doesn't work also.I also tried hotmail but it causes the same problem.I am using Python 2.7 (don't ask :) ) on a Windows 7 machine developing on Eclipse using PyDev.
Any help would be great!
Thank you in advance.
I'm using the same construct on one of my servers. My code is below.
The only difference is the extra .ehlo() after '.starttls()`. This should not be the issue; from the RFC:
5.2 Result of the STARTTLS Command
The client SHOULD send an EHLO command as the first
command after a successful TLS negotiation.
According to the RFC, the server should not sever a connection if the client does not send ehlo after starttls, but Google could be more restrictive on their SMTP server. I'd check that first. (I've seen providers tighten down on these kinds of conditions to reduce spam, see Mailinator's 2007 writeup for instance.)
It could also be filtered ports - try running the code in the REPL and confirm which line is exceptioning, if it's the connect() you'll know it's network. If it's after, it's likely your usage of smtplib.
Of note, I also experienced occasional unclean shutdowns, resulting in the try/except around .close().
import smtplib
s = smtplib.SMTP()
s.connect("smtp.gmail.com")
s.ehlo()
s.starttls()
s.ehlo()
s.login("from#gmail.com", "frompass")
s.sendmail("fromname#gmail.com", toAddr, bytes)
try:
s.close()
except: pass
Well, since I cant post comments yet I'll have to attempt an answer..
Judging by this: Python SMTP Errno 10060
Perhaps a timeout would help?