13

What I'm supposed to do is send emails from Ubuntu. The easiest way I have found is using Thunderbird and linking my real e-mail address ([email protected]) to Thunderbird account. I can successfully receive e-mails and download full history this way. I can't send e-mails, however.

What I want to do is send e-mails straight from Ubuntu and appear as user1@localhost or something similar.

Is that even possible? After reading different topics about this, It seems that using a relay address is the only way.

I have also installed Postfix, same way as written there: How to set up a mail server? When I was asked to choose installation type, I chose Internet site.

Options I had:

  • No configuration;
  • Internet site;
  • Internet with smarthost;
  • Stellite system;
  • Local only;

When asked for system mail name, I entered a website I own: some_website.com . I still haven't figured out how to send emails bia postfix but I assume that again a relay-server will be used.

I'm running Ubuntu 11.10 as a virtual machine.

I hope this question makes sense.

3 Answers 3

13

It does not make perfect sense because you have said, "supposed to do," as though it is your job. Are you setting up a real mail server within a virtual machine? I take the clues to mean that you need the virtual server to have a mail system, but that the virtual server is not a full-time "real" SMTP server. (Otherwise you would know already, I guess wildly.)

With that in mind, you would need the "Internet with smarthost" option. Essentially, the big reason is that well-configured SMTP servers around the world all use anti-spam measures; and, among these measures is the rejection of all SMTP connections that come from known pools of dynamic addresses (that spammers love to use). Therefore, you need to use another SMTP server for outgoing mail.

If you want to stick with Postfix for this, it is easy to do: just search for Ubuntu articles related to setting up Postfix as a smarthost. However, if you have no particular affinity for one system over another, there is a package designed just for this: ssmtp. So, if you want to give it a spin, then just install ssmtp.

(Caution: the action below will remove postfix or sendmail.)

sudo apt-get install ssmtp

Then edit the ssmtp configuration file:

sudo -e /etc/ssmtp/ssmtp.conf

I do not know details of an SMTP server available to you, so I will give a GMail example:

[email protected]
Mailhub=smtp.gmail.com:465
RewriteDomain=gmail.com
AuthUser=your_gmail_username # [email protected]
AuthPass=your_gmail_password
FromLineOverride=Yes
UseTLS=Yes

Now your system will send mail the way you want. You can use localhost as a mail server in your GUI applications for the outgoing SMTP server. But what about the CLI? Use the mail software:

sudo apt-get install heirloom-mailx

Now you can also use mail from the command line with something like:

mail < filename.ascii [email protected] -s "My File"

Or, if you use mail to compose a message you type (mail [email protected]), then finish off the mail message with a single period on a blank line. A better CLI mail client is mutt or pine.

Is this the angle you needed? If so, was it successful?

9
  • 1
    Mutt says "sendmail: Cannot open: 25" when I try to send an e-mail. ssmtp says "ssmtp: cannot open: 25" I also said I can send e-mails via Thunderbird, but I think I was wrong. Sorry about that. I get timed-out when sending trying to send e-mails via Thunderbird, and messages about port 25 when using CLI mail clients.
    – afaf12
    Jan 1, 2012 at 4:15
  • @afaf12 check whether firewall is blocking. Connection timeout error mainly occurs due to firewall issue.
    – Mughil
    Jan 1, 2012 at 12:07
  • 1
    Does the remote mail server restrict access to certain address ranges, by configuration or firewall?
    – user8290
    Jan 1, 2012 at 12:52
  • Do you need to use on this remote mail server the submission port: 465?
    – user8290
    Jan 1, 2012 at 23:01
  • I cannot getsudo /etc/init.d/ssmtp restart workable on my machine.
    – Nam G VU
    Jun 21, 2012 at 9:58
1

If you are using Thunderbird, you can configure a remote server for SMTP. Unless you have a mail server of your own, this would normally be your ISP's relay server, or your mail providers SMTP server. I have successfully used Gmail as my SMTP server, but it does require authentication. (Some of the other hosts may as well.)

Test access to the server with the command telnet mail.example.com 25. If it is working, you will get a banner message from the server.

Once you have Thunderbird working with the server, you can configure Exim or Postfix as a satellite server for the same server. You can skip this if you don't need to send email off the system from other applications. Be careful, that the source address on the outgoing server can accept email.

EDIT: Check that you don't have iptables activated and blocking outgoing traffic. If you do, enable outgoing traffic on your desired port. You can use a command like tcptraceroute mail.example.com 25 to see where you are getting blocked. tcptraceroute would need to be installed before you use it.

1
  • Telnet: Unable to connect to remote host: connection timed out. I am sure that remote server can accept mail on port 25. I have succesfully send emails to this remote server from other machine (windows 7).
    – afaf12
    Jan 1, 2012 at 10:58
0

I tested this on a vagrant box and working perfectly. Installed following things by running the command

apt-get install php-pear

pear install mail

pear install Net_SMTP

pear install Auth_SASL

pear install mail_mime

Then install postfix by running following command

apt-get install postfix

during installation Select--

Internet Site and localhost in place of server because we trying this on localhost

After this run the following command

sudo vim /etc/ssmtp/ssmtp.conf

to make changes to files

make this changed to ssmtp.conf file

FromLineOverride=YES

[email protected]

AuthPass=yourpasss

most important make your email accessible to less secure apps by

https://www.google.com/settings/security/lesssecureapps

and then you can use php mail function or Enter following command in terminal to send mail from terminal itself

$ ssmtp [email protected]

From :[email protected]

TO :[email protected]

Subject:The Subject

Hello this is my first ssmtp email!.

press Ctrl+D and ssmtp will send your email

You can also check the smtp is working or not from your machine

ping smtp.gmail.com

--output from this command is something like

64 bytes from sc-in-f108.1e100.net (74.125.68.108): icmp_seq=1 ttl=63 time=68.4 ms

telnet smtp.gmail.com 587

--output must be something like this

Trying 74.125.68.108...

Connected to gmail-smtp-msa.l.google.com.

220 smtp.gmail.com ESMTP l14sm12513264pfb.73 - gsmtp

You must log in to answer this question.

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