How do I set up my Ubuntu VPS to send outgoing mail?

1,773

Solution 1

Have you looked here, seems to me that there is plenty of information to get started. I found mail-server-slice-setup to be quite informative.

Solution 2

To my experience, when email providers check for spams, they check 5 main things other than content: (When I say domain, I'm referring to the domain of the sender's email address.)

  1. "A" record (IP) of the domain name exists
  2. MX records of the domain name exist
  3. PTR record (Reverse lookup) of the sender's IP address exists (Sometimes, I think it is also checked to see if the PTR record has the same A record as the original domain)
  4. SPF record of that domain matches the IP number (This is a list of IP numbers allowed to send emails of that domain. Although this would be a great solution for spam filtering, this is not an official record, so it is not always checked. Check out the SPF setup wizard.)
  5. The IP segment of the server is not a blacklisted segment.

The fifth one is the one that was a problem for me. Apparently email providers such as Hotmail, Gmail, Yahoo drop all incoming email from widely used server providers such as Amazon EC2. In that case, there's simply no way to guarantee the delivery of all outgoing emails, so you would have to relay all outgoing email from some other SMTP server outside the blacklisted segment. The easiest way to do this is configuring Postfix (or whatever MTA you're using) to automatically relay all emails. You can find plenty of articles on this if you do some googling.

If that is not the case, then all you need is a simple MTA like Postfix, as long as all the necessary DNS records listed above are configured properly, you should have no trouble sending emails.

Solution 3

Other answers have provided information about the mechanics of sending email, but one thing you need to consider is what sender address you're going to use, and how you're going to deal with bounce messages.

Let's say you're sending emails from [email protected]; then (as Murat Ayfer noted) you need to make sure that your host is allowed to send mail according to example.com's SPF record. (This may or may not be configured by IP address -- see the SPF site for more details.) If you're in charge of the example.com domain, then this shouldn't be a problem. Being listed as an acceptable sender for the domain is an important step towards your emails getting through.

The next thing you need to worry about is how to deal with bounced emails. If some other host receives emails for example.com (i.e. the MX record points elsewhere), then it's mainly someone else's problem. (Note however that your application has to be prepared for a failure during the SMTP session to the mailserver on your host, due to syntactically invalid email addresses, for example.) But if you decide that you'll receive mail for example.com on your host, then you need to worry about dealing with retry messages, bounce messages, double bounce messages, and a whole lot of other general mail server administration. There's some info on handling undelivered emails in web applications which might be helpful, but I also suggest getting a good book on Postfix or whatever mail server you decide to use.

Share:
1,773
shlomi
Author by

shlomi

Updated on June 04, 2022

Comments

  • shlomi
    shlomi about 2 years

    I'm making a batch file (*.bat) for myself to try make some things easier file where I enter commands with adb.exe. The problem is, any code after 'adb shell' is not executed in the batch. So if I had a batch with the following:

    adb shell
    cd /storage/emulated/legacy/
    mkdir $(date +%d-%m-%Y)_OniFiles
    mv *.oni $(date +%d-%m-%Y)_OniFiles
    adb pull /storage/emulated/legacy/$(date +%d-%m-%Y)_OniFiles C:/$(date +%d-%m-%Y)_OniFiles
    

    'cd /storage/emulated/legacy/

    mkdir $(date +%d-%m-%Y)_OniFiles

    mv *.oni $(date +%d-%m-%Y)_OniFiles

    adb pull /storage/emulated/legacy/$(date +%d-%m-%Y)_OniFiles C:/$(date +%d-%m-%Y)_OniFiles'

    will not be executed and stays at '$'. It seems like it's too deep for a batch file to enter codes. I also tried pushing a sh with the same script and run it from adb but then all I get it permission denied.

    I have also tried 'adb shell cd /storage...' without any luck.

    Can you help me? Thanks!

    • Endoro
      Endoro over 10 years
      md "%date:~6,4%-%date:~3,2%-%date:~0,2%"
    • shlomi
      shlomi over 10 years
      Hi, I don't have a problem with the date. The problem is that when I put all commands in a batch file, It's only execute the first line, (adb shell) and not the cd.
    • foxidrive
      foxidrive over 10 years
      Is this in Windows or Linux? Your commands aren't structured for Windows. Linux doesn't do *.bat files.
  • Scott Bennett-McLeish
    Scott Bennett-McLeish over 15 years
    Coincidentally, I've been pondering getting a slice going some day soon, this might've just given me that last little shove to do it.
  • Scott Bennett-McLeish
    Scott Bennett-McLeish over 15 years
    Also found this (jonsview.com/2008/07/14/…) which could be handy.
  • shlomi
    shlomi over 10 years
    Thanks but it's not working. It's seems like when it open the adb shell it's stop running all other commands in the script.
  • shlomi
    shlomi over 10 years
    Hi, thank you for your answer. My problem is that when I run the batch file I describe, it's only execute adb shell, and not continue with the other commands, like cd /storage/...
  • MC ND
    MC ND over 10 years
    ´adb shell´ opens an interactive shell on the remote device. So, it sits waiting for you to give commands. It's necessary to indicate the commands. So adb shell "command" executes the command on the device and returns to the calling batch file (so says the documentation, i can't try).
  • shlomi
    shlomi over 10 years
    So the question is how can I run a batch file with the commands?
  • MC ND
    MC ND over 10 years
    have you readed the answer? run in sequence multiple adb shell "command". Or if this is a repeating task, put a shell script in device and use the indicated method to call it from pc.
  • Endoro
    Endoro over 10 years
    in some cases all support will not be successful. In this cases, the user should use better a GUI application, eg. AutoIt.