Search code examples
pythonemailserverhostingubuntu-server

How to send email without port forwarding?


I want to know, that how can I send email without port forwarding. I am just interested in sending the email (not interested in receiving the email). I want to send the email from my own SMPT server. It's appreciated if you also guide me with the whole process.


Solution

  • The easiest way I found to send an email is calling the blat app. It is not elegant, but works. The example should work after you change server and email addresses:

     import subprocess
     subprocess.call('blat -to to@you.com -subject "hey" -body "Body" -server mail.SMTPServer.com -f from@you.com', shell=True)
    

    I just realized you tagged Ubuntu. You can do exactly the same thing using your choice of built in Linux email clients, although you will have to look at the man pages. Experiment by sending an email completely from the command line, when it works, paste the line into the subprocess.call.