I'm trying to send a message from localhost:1025. I'm running an SMTP debug server using this command python -m smtpd -n localhost:1025.
Here is the code used for sending the mail:
msg = mailer.Message(From='noreply#'+company['host'],
To=req['mail'],
Subject='E-mail confirmation',
Body=Template(open('./confirmation.html').read()).render(company=company, account=account, accode=accode))
mailer.Mailer(company['host'], port=1025).send(msg)
The req['mail'] contains my email address, when I checked my email inbox and spam folders, I didn't find any message - What's, supposedly, caused this problem?
As is made quite clear in the documentation the debugging server does not attempt to deliver email messages. This is to allow testing and verification of the email's content without actually sending any mail.
Related
I have written a code in jython 2.5, which uses the smtplib sendmail to send mail over a smtp server. Below is a simple snippet of the code
mail = MIMEMultipart('mixed')
mail['Subject'] = mail_subject
mail['FROM']=UstrSender
mail['To']=UstrReceivers
mail['Cc']=UstrCC
mail_p2=MIMEText(mail_html, 'html', 'utf-8')
mail.attach(mail_p2)
#Connection to SMTP
#Enter SMTP Server Details, In case your server do require authentication modify authentication parameter below and uncomment
s = smtplib.SMTP(smtpserver)
#s.sendmail(UstrSender, [UstrReceivers, UstrCC], mail.as_string())
sendmail_return = s.sendmail(UstrSender, [UstrReceivers, UstrCC], mail.as_string())
Now, the smtp server mentioned is a cluster of 3 individual servers and there is a lag at times on one of these servers because of a long queue of requests. To identify such issues and the culprit server, need to have a generic script to identify the queue id of the message being sent. Kindly, help on the same, if using docmd we can create such a command to get the queue id of the submitted email.
I tried getting a response from sendmail itself, but since the mail is eventually sent, there is no return from the command.
Thanks,
Dev
I am trying to send email from a DigitalOcean droplet (Ubuntu 16.04 32 bit) in python3.5 using the local mail/smtp server, primarily to a gmail account. However, currently no errors are displaying from my python script or the server command, but the emails are not showing up in my gmail inbox or spam folder.
I have also followed similar steps from my laptop where possible, with no results.
I want to use the local mail/smtp server to send emails to avoid storing authentication details in the server, and since it will not be receiving emails then I am not as worried about security as if receiving (e.g. not worried about injection attack).
To start off, I run the command;
python3 -m smtpd -n -c PureProxy localhost:1025 &
I run the following script. My understanding is that this should send the email to the local mail/smtp server, which should then handle ensuring it's delivery.
import smtplib
from email.mime.text import MIMEText
msg = MIMEText('test message from droplet body')
msg['Subject'] = 'test message from droplet subject'
msg['From'] = 'droplet#mydomain.com.au'
msg['To'] = 'mygmailusername#gmail.com'
s = smtplib.SMTP('localhost', 1025)
s.set_debuglevel(True)
s.send_message(msg)
s.quit()
With the above method, no error messages occur. However the emails are never received. All methods I have tried so far have had this result.
Using the DebuggingServer instead of PureProxy and the same steps as before provides output similar to below;
---------- MESSAGE FOLLOWS ----------
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: test message from droplet subject
From: droplet#mydomain.com.au
To: mygmailusername#gmail.com
X-Peer: 127.0.0.1
test message from droplet body
------------ END MESSAGE ------------
I have tried the first example on the following page
https://docs.python.org/3/library/email-examples.html
However this fails due to a refused connection error.
I have also tried to check the spamminess of my domain's emails using the following site, however it times out - this indicates to me that it may be a problem with DigitalOcean allowing emails through it's firewall.
https://www.mail-tester.com/
I have checked reputation of my domain using this site - it says it is neutral (using talosintelligence link in comments)
I have tried sending email using the prior instructions to my namecheap private email, but without success.
One possibility I read about is that a PTR DNS record needs to be set, to allow reverse DNS lookup. I am not sure what to do with this though, and I would have to override the default droplet name.
Extra details
I am using a .com.au domain registered with namecheap. I am also using a private email service with namecheap, which required setting multiple DNS records including MX - I added all on the following link, including the optional ones, on my digitalocean account (link in comments)
I also set up the digitalocean nameservers on the namecheap account (link in comments)
I can send and receive email on the private email service.
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
I have a Flask application that uses an email server at Bluehost to send mail. Flask-mail successfully sends the email (I don't see any errors in the logs) however the email never arrives to Gmail accounts (not in spam or anything either). However, it does arrive at other domains.
Any idea what may be causing this or where to look for errors?
Thanks!
I just check your SPF records.
It seems that your sending mail server has no SPF record. This is why Gmail is probably blocking email from you mail server.
Check here for more info: this
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.