2

I've finally moved to Ubuntu 14.04 from Windows. I had xampp installed for web development.

For testing of sending/receiving emails I used this tool http://www.toolheap.com/test-mail-server-tool/users-manual.html Things were straight forward. I send email using PHP, it's saved and opened automatically in Windows Live Mail. How can I achieve that in Ubuntu?

I currently have LAMP installed. Where to go next?

Thanks, Fouad

5
  • What would you like to do? Send an email and check if it arrives at the destination? If so, use echo 'This is a test' | mail -s "Hello test world" [email protected]
    – Jan
    Oct 29, 2014 at 9:22
  • I would like to send emails from PHP, receive them locally to see how they are rendered
    – f.farah
    Oct 29, 2014 at 9:28
  • I also apt-get install sendmail then apt-get install postfix chose the local option in the config
    – f.farah
    Oct 29, 2014 at 9:30
  • There is a php mailer in github. You can adjust the code to your needs.
    – kukulo
    Nov 1, 2018 at 14:47
  • github.com/PHPMailer/PHPMailer
    – kukulo
    Nov 1, 2018 at 14:47

3 Answers 3

3

I finally figured it out after a month! This is how it is done

  1. Create a folder in your Documents named TestEmails

  2. Open the terminal and enter the following command

    sudo chmod 777 ~/Documents/TestEmails/

  3. Open the php.ini file that is located in your /opt/lampp/etc directory

  4. Press CTRL+F and then type "mail function"

  5. Under the [mail function] remove comment from sendmail_path

  6. Set sendmail_path to sendmail_path = "cat > /home/USERNAME/Documents/TestEmails/date '+%Y-%m-%d - %H-%M-%S'.eml" BUT MAKE SURE TO REPLACE USERNAME with your own username

  7. If Apache is running, restart it

2
  • 1
    That's actually an interesting way of testing without having an e-mail server configured.
    – vidarlo
    Jun 20, 2019 at 20:02
  • I think this is a better command sendmail_path = "NOW=$(date +'%Y-%m-%d - %H-%M-%S'); FILE=/opt/lampp/htdocs/TestEmails/$NOW.eml; cat > $FILE;" (make sure you have binutils) Dec 16, 2020 at 22:36
1

The easiest solution would be to use MailCatcher: https://mailcatcher.me/

An in my opinion better alternative is postfix with pcre to have a proper catch-all.

Setup a Local Only Email Server.

  1. Point localhost.com to your machine

    Most of programs will not accept an email using just @localhost as domain. So, edit /etc/hosts file to make the domain localhost.com point to your machine, including this content to the file:

    127.0.0.1 localhost.com
    
  2. Install Postfix

    sudo apt-get install postfix postfix-pcre  
    
  3. Configure Postfix to Local only.

    During postfix install process, the configure text dialog will display five options:

    General type of mail configuration:

    No configuration Internet Site Internet with smarthost Satellite system Local only

    Select "Local Only".

    For the domain name, use the default suggested and finish the install.

  4. Configure a Catch-all Address

    Enabling this, you can use any email address.

    Example: here, my unique account is [email protected]. But while testing systems, I can use any address like [email protected], [email protected], etc., because all will be redirected to [email protected]

    If it dies not exist, create file /etc/postfix/virtual: sudo nano /etc/postfix/virtual

    Add the following line content, replacing with your user account:

    /.*/ <your-user>
    

    Save and close the file. Configure postifx to read this file:

    Open /etc/postfix/main.cf: sudo nano /etc/postfix/main.cfand check if this line is enabled, or add it if not exists:

    virtual_alias_maps = pcre:/etc/postfix/virtual
    

    Activate it: sudo postmap /etc/postfix/virtual Reload postfix: sudo systemctl restart postfix If you're under non-systemd distro, like Ubuntu 14.04, service restart command probably is: sudo service postfix reload

  5. Install Thunderbird.

    sudo apt-get install thunderbird`
    
  6. Configure Thunderbird.

    Skip the welcome screen (click in the button to use existing accounts); Click in the Settings button at top right (similar to Chrome settings) then click on Preferences > Account Settings Under Account Actions choose "Add Other Account" Select "Unix Mailspool (Movemail)" Your account will be @localhost (of course, replace with your user account). Don't use @(none), use @localhost Outgoing server will be: localhost at port 25. Restart (close and reopen) Thunderbird.

  7. Start your Mail Spool file

    This step have two purposes: test your install and stop the Unable to locate mail spool file. message. Using Thunderbird, send new email to @localhost, replacing with your user account Click on "Get Mail" Test catch-all: send new email to averagejoe@localhost Click on "Get Mail" and you'll see the message at Inbox.

2
  • I found out about mailcatcher literally yesterday, part of the env for a client, looks great
    – f.farah
    Nov 2, 2018 at 7:30
  • about postfix way - thunderbird was dropped "Unix Mailspool (Movemail)" support, so it makes no sense now...
    – Dmitry
    May 20, 2022 at 9:11
0

Try

sudo apt-get update
sudo apt-get install postfix

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .