I am sending emails using smtplib using internal relay.
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = server
s = smtplib.SMTP('SMTP', port)
s.send_message(msg)
s.quit()
Access is controlled with an ACL and I would like to be able to fire my script from my local machine through an intermediary host that is allowed on the SMTP relay. Until now I have been sshing to the intermediary host but that's a bit of a palaver to be honest.
How would I go about tunneling this traffic so SMTP relay would see the request came from intermediary host?
PS. All actions are done within a domain environment. I just want communication to flow from my hostname, through another host that is allowed on our local smtp relay.
Related
I want to create a program ,which can send bulk emails to people (for company purposes).
For a few emails I used gmail.smtp.com for sending mails
s = smtplib.SMTP('smtp.gmail.com', 587)
# start TLS for security
#s.starttls()
# Authentication
s.login("myemail#gmail.com","mypassword")
# message to be sent
message="hello"
# sending the mail
s.sendmail("myemail#gmail.com", "targetemail#gmail.com", message)
# terminating the session
print("mail sent")
s.quit()
I know that I cannot use Gmail's SMTP server for sending bulk mail.
How do I set up a local SMTP server and use it in smtplib?
I have searched many python email related post here but I seem not able to send a single email using python. I am working within corporate LAN. But If I use my company's smtp relay server I am able to send email to gmail, or my company ID or other emails.This is very strange or it is suppose to be this way? How can I use gmail smtp server to send email outside?
Here are few scripts I have tried.
====================================1==
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("xyz#gmail.com", "myPasswd")
msg = "YOUR MESSAGE!"
server.sendmail("xyz#gmail.com", "xyz#gmail.com", msg)
server.quit()
===================================2==
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
msg = MIMEMultipart()
msg['From'] = 'sender#gmail.com'
msg['To'] = 'recvr#gmail.com'
msg['Subject'] = 'simple email in python'
message = 'here is the email'
msg.attach(MIMEText(message))
mailserver = smtplib.SMTP('smtp.gmail.com',587)
# identify ourselves to smtp gmail client
mailserver.ehlo()
# secure our email with tls encryption
mailserver.starttls()
# re-identify ourselves as an encrypted connection
mailserver.ehlo()
mailserver.login('sender#gmail.com', 'pswd')
mailserver.sendmail('sender#gmail.com','rcvr#gmail.com',msg.as_string())
mailserver.quit()
======================================
I am sure it is nothing to do with code but something else I am missing.
I had the same problem
It seems that google find your application is insecure. You can:
Allow less secure applications to connect to the server in google apps settings. see Allowing less secure apps to access your account
Secure your code [whatever it means by google ...]
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'm building and testing a web service on my local machine before i put it in production. I want to test the mail service. I'm using the standard python email and smtplib libraries.
import smtplib
from email.mime.text import MIMEText
fp = open('textfile', 'rb')
msg = MIMEText(fp.read())
fp.close()
me = 'me_email#localhost'
you = 'me_again_email#localhost'
msg['Subject'] = 'The contents of %s' %fp
msg['From'] = me
msg['To'] = you
s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()
I have not configured sendmail and hence it throws an error. But since I just want to test my web service I am not concerned if sendmail cant send an email right now. My service is designed to pulls some records off db and send them an email. So i want to know if this connection, python taking inputs from db and pushing an email is working. I want to receive the email on localhost sent via the script.
An SMTP server needs to be configured for sending emails. Sending emails is not possible unless you configure an SMTP server. More information on using python smtplib can be found in pymotw.com, tutorialspoint.com and Python docs.
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?