How to make an SMTP Server in Python to send email? - python

I was looking around, but I couldn't find a really definite way to setup an SMTP server in Python that can just send messages. I saw inbox.py, but there was a lack of documentation and I couldn't figure out how it works. I don't need to save emails to files, all I need is the ability to send them.
Thanks for any recommendations!

Related

What's the best way to setup a google smtp server for noreply E-Mails sent from a Python application?

We are currently developing a python program that as part of its functionality sends noreply E-Mails to customers whenever something important happens. For testing we are sending them from a free noreply#gmail.com address using pythons smtplib library and that works without problems so far.
However when going live we want to change the address to a proper noreply#company.com address. We are already using Google workspaces and have user accounts with company E-Mails. But while reading up on how to get that to work I came across multiple guides and articles which were either confusing, outdated or don't really do what I was hoping for. So I have a few questions that I hope you could answer.
Do I have to create a new user account just for the noreply mails? I have read about aliases and groups but I am not sure that this is the right way to do it since the mails shouldn't be sent from a renamed existing user account. I'd rather not set up a user just for sending E-Mails.
How many mails can I send when it is all set up? Free accounts can send 500 daily, workspace users have 2000, up to 10000 with smtp relay (if that's possible)? If the program ever exceeds this limit is there any way to increase it or should I already look for an alternative.
Finally how do I set this up? Most guides are for the old Gsuite. I feel like there should be an easy way to set this up that I am missing. All I'm looking for is creating a generic noreply#company.com address for our project to programmatically send a higher amount of mails.
Thanks for the help.

Python SMTP Server protocol

I want to build a simple SMTP-Server by using Python which has the ability to authenticate users through default authentication method. No SSL/TLS is needed.
I was able to start a listener on port 25 and connect to different SMTP-Clients like Outlook to log the requests but it seems like it is too complicated to build it by myself.
Is there any library for Python which allows me to create a SMTP-Server and handle the messages by myself? For example, do not send it, but only save a ".eml" file or something.
Thanks for your help!
You should try smtplib
This is the native SMTP library used in Python. Probably is the best to start here and, if you miss something, find a library more robust.
Edit:
For server, you should try SMTPD

Writing an email sending program in Python

I want to write an email sending script in Python. Most email programs have to connect to existing servers, like Gmail or Hotmail. I want my script to work independantly of those servers and just be able to send email itself (without having to logon anywhere else). The reason for this is because most email servers (like Yahoo) limit what you can do, such as controlling the sender address or sending certain types of files. So I wanted to write my own script to get around that. So what do I do? Where do I begin learning how to do this? Do I have to write my own server? If I do, how is that done?
You need an MTA (a.k.a. mail transfer agent), whether it's local or remote. SMTP servers talk to each other to deliver the mail through — if you don't want to connect to the remote one, you need to run a local one. Look into Postfix or exim — just be careful not to allow random people to connect to it. Go to Server Fault if you need help with configuring them.
This is language-agnostic, BTW.
The email-module of Python should give you a good starting point. Btw this was the first hit when googling Python email.
You'll essentially need to set up your own mail server. I prefer postfix but there are several alternatives, you'll have to google this one.
Once you can send email through your own server, look into smtplib or email-library for sending email with Python

How do I receive mail using Python?

I am trying to make a program on my computer at home that will constantly check a certain gmail address; The purpose being the only email this address receives is from me.
I would just like to be able to
Check for mail
Download mail (presumably to a string, though a file is acceptable), and
Delete the mail from the web server but keep it on my computer.
That is all I need to know right now, however my long term goal is to set up kind of a remote terminal over email, so that wherever I have email I have a certain amount of control over my computer.
As Gabi points out, you should check out libgmail. You might also want to check out twisted python. They have some powerful modules for SMTP, POP3, IMAP, and many more that have nothing to do with email.
If you want to write a program to just process incoming e-mail, take a look at Pythomnic framework: http://www.pythomnic3k.org/

How to best implement simple crash / error reporting?

What would be the best way to implement a simple crash / error reporting mechanism?
Details: my app is cross-platform (mac/windows/linux) and written in Python, so I just need something that will send me a small amount of text, e.g. just a timestamp and a traceback (which I already generate and show in my error dialog).
It would be fine if it could simply email it, but I can't think of a way to do this without including a username and password for the smtp server in the application...
Should I implement a simple web service on the server side and have my app send it an HTTP request with the info? Any better ideas?
The web service is the best way, but there are some caveats:
You should always ask the user if it is ok to send error feedback information.
You should be prepared to fail gracefully if there are network errors. Don't let a failure to report a crash impede recovery!
You should avoid including user identifying or sensitive information unless the user knows (see #1) and you should either use SSL or otherwise protect it. Some jurisdictions impose burdens on you that you might not want to deal with, so it's best to simply not save such information.
Like any web service, make sure your service is not exploitable by miscreants.
I can't think of a way to do this without including a username and password for the smtp server in the application...
You only need a username and password for authenticating yourself to a smarthost. You don't need it to send mail directly, you need it to send mail through a relay, e.g. your ISP's mail server. It's perfectly possible to send email without authentication - that's why spam is so hard to stop.
Having said that, some ISPs block outbound traffic on port 25, so the most robust alternative is an HTTP POST, which is unlikely to be blocked by anything. Be sure to pick a URL that you won't feel restricted by later on, or better yet, have the application periodically check for updates, so if you decide to change domains or something, you can push an update in advance.
Security isn't really an issue. You can fairly easily discard junk data, so all that really concerns you is whether or not somebody would go to the trouble of constructing fake tracebacks to mess with you, and that's a very unlikely situation.
As for the payload, PyCrash can help you with that.
The web hit is the way to go, but make sure you pick a good URL - your app will be hitting it for years to come.
PyCrash?
Whether you use SMTP or HTTP to send the data, you need to have a username/password in the application to prevent just anyone from sending random data to you.
With that in mind, I suspect it would be easier to use SMTP rather than HTTP to send the data.
Some kind of simple web service would suffice. You would have to consider security so not just anyone could make requests to your service..
On a larger scale we considered a JMS messaging system. Put a serialized object of data containing the traceback/error message into a queue and consume it every x minutes generating reports/alerts from that data.

Categories

Resources