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.
Related
I am currently trying to send emails via smtplib with the following code:
import smtplib
import email.utils
from email.mime.text import MIMEText
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo()
smtpserver.login('username#gmail.com', 'pwd')
msg['Subject'] = "subject line"
msg['From'] = 'newusername#gmail.com'
msg['To'] = 'friend#gmail.com'
smtpserver.sendmail(sender, recipients, msg.as_string())
When I do something like this, instead of the recipient getting an email from newusername#gmail.com, they get it from username#gmail.com, which was the email I used for authentication.
Is there a way to change this?
This is an intentional security feature in gmail, and other public mail servers, called SMTP AUTH.
Without this feature, anyone with a gmail address could send mail impersonating anyone else with a gmail address. I could send a message claiming to be from you, and the recipient would have no way of knowing it wasn't from you, and you'd have no way to prove it wasn't from you.
But it wouldn't matter anyway, because spammers would be sending so much more email with your address than you do that email addresses would be effectively meaningless, and the whole email system would fall apart. Which is what almost happened in the late 90s. Only a concerted campaign to require SMTP AUTH on all open submission servers, including blacklisting all mail from servers that didn't comply (even the ones that used POP-before-SMTP, IMAP-before-SMTP, IP/MAC verification, or other alternatives to SMTP AUTH) managed to keep the spammers from ruining everything.
Later, another security/anti-spam measure, called DKIM, was added, which gmail also uses: most servers will throw out any messages that isn't signed by the originating server, indicating that the server trusts that the message came from who it says it came from. Obviously, gmail isn't going to certify that a message came from newusername when it actually came from username.1 And, if they did, people who administer other servers would just blacklist gmail signatures are meaningless.
1. Unless they have some reason to trust that username has the right to send mail as newusername—corporate mail servers sometimes do have a feature like that, allowing you to configure things so, e.g., a secretary can send mail from his boss's address without having his boss's password.
I am trying to send emails to a private SMTP server and can do so using python smtplib as follows
s = smtplib.SMTP(server, port)
s.sendmail(me, you, msg.as_string())
Trying to convert the same to Sendgrid (as Azure blocks SMTP) but it has no option to specify a private SMTP server.
import sendgrid
import os
from sendgrid.helpers.mail import *
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
from_email = Email("test#example.com")
to_email = Email("test#example.com")
subject = "Sending with SendGrid is Fun"
content = Content("text/plain", "and easy to do anywhere, even with Python")
mail = Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body=mail.get())
print(response.status_code)
print(response.body)
print(response.headers)
Any help would be much appreciated.
Thanks
That's quite normal, the python package for sendgrid does not use the smtp protocol, but actually request an API which use classical HTTPS requests...
So, except if your smtp server can be accessed over an API (custom-made?), there's no chance you can use the sendgrid package.
If you want to customise the python package for sendgrid in order to point toward your own API endpoint which will act as relay for your smtp requests, you are free to modify its source code: https://github.com/sendgrid/sendgrid-python
Alternatively you can use port 2525 since all major smtp vendors support it and its not blocked by Azure as far as I know. But if your smtp server is something not from a major vendor and you do not have access to it to change/add ports you have no option but to go to a service other than Azure for hosting which might be hard since all major vendors now block 25, 465, 587.
I made a simple keylogger in C++. I want to send an email with the input the keylogger made using Python. I know you can do it with C++ but I want to use Python.
You I hope that your keylogger is for educational purposes only. Anyway,
here is a simple way to send one e-mail using Python script.
#!/usr/bin/python
import smtplib
sender = 'from#fromdomain.com'
receivers = ['to#todomain.com']
message = """From: From Person <from#fromdomain.com>
To: To Person <to#todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
Here, you have placed a basic e-mail in message, using a triple quote, taking care to format the headers correctly. An e-mail requires a From, To, and Subject header, separated from the body of the e-mail with a blank line.
To send the mail you use smtpObj to connect to the SMTP server on the local machine and then use the sendmail method along with the message, the from address, and the destination address as parameters (even though the from and to addresses are within the e-mail itself, these aren't always used to route mail).
If you're not running an SMTP server on your local machine, you can use smtplib client to communicate with a remote SMTP server. Unless you're using a webmail service (such as Hotmail or Yahoo! Mail), your e-mail provider will have provided you with outgoing mail server details that you can supply them, as follows:
smtplib.SMTP('mail.your-domain.com', 25)
Source: http://www.tutorialspoint.com/python/python_sending_email.htm
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?
I am developing my first website. I have page where people can leave message to me. What I am doing is sending a AJAX call to the server, and the server gets the content of the message, then login in an gmail account and send the message to another gmail account using python's email libraries smtplib and email.
It works ok, but the problem is it takes more than one minute on my laptop, the loading image on the client side would keep spinning during the time. I think the bottleneck is login().
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
# login, send email, logout
mailServer.login(conf.user, conf.pw)
mailServer.sendmail(conf.user, to, msg.as_string())
mailServer.close()
So is there any way to speed this up, or other ways to do this.
Thanks
So the delay is probably caused by Google's SMTP server as they do a reverse lookup of the IP address of your webserver - mail systems often do this as part of sending e-mail.
What you have coded is only needed if you intended to send mail out from your account - that is when you need to perform authenticated SMTP. If you want to only mail your own account then you can remove the login step. Note, that you will have to change the mail server from smtp.gmail.com to one of Google's inbound mail (MX) servers. Also, if you are performing a simple forward you will have to handle e-mail rejection or other connection problems so having your script dump the mail to a simple mail server running on the mail server would be helpful.