1. Ubuntu 14.04 on a virtual machine that is not my PC. I use my PC (Windows 7 and Putty 0.63) to shell into it.
  2. Uname=Linux ubuntucomp 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
  3. This machine is on our private network and does not have an official registered domain name. It has it's own IP but I think it's an internal IP. This machine is not accessed from outside our network, I only use it to send outgoing emails to people in our company. I got Perl to send an email out to our SMTP provider and that works fine.
  4. We pay for an external SMTP service, so that part is done. The only SMTP authentication I use is a username and password. SSL is not needed.
  5. I have no intention of receiving any email from the outside world on this machine.
  6. Right now my emails are being blocked by my SMTP provider, possibly because I don't have a FQDN. The error I get is "connection timed out".
  7. I can't even telnet from my PC to the SMTP server, I also get a "timeout" error. I used Putty 0.63. Yet I can still send email via a Perl program on Ubuntu.
  8. IT cannot help me so I'm on my own. I'm new to sysadmin for Ubuntu.

I need a way to send emails with an attachment via the command line (for an automated cron process) without setting up a registered domain, MX or A record. What are my options? Postfix won't do this as it requires a bunch of network settings set up along with a (DNS?) record.

Since the Perl module uses the SMTP protocol to directly log into the SMTP server, I suspect I need an Ubuntu package that does the same, without passing the task onto another MTA.

I tried SSMTP

  1. Using ssmtp I got this error from /var/log/mail.log: Oct 22 10:18:19 ubuntucomp sSMTP[16075]: Unable to connect to "smtpout.payserv.net" port 587. Process failed with error code 1. Oct 22 10:18:19 ubuntucomp sSMTP[16075]: Cannot open smtpout.payserv.net:587
  2. In /etc/ssmtp/ssmtp.conf I even changed the setting "Rewritedomain" to be our actual company domain name.
  3. And how do I restart the SSMTP daemon after I make changes to the ssmtp.conf file? Perhaps that's part of the problem.

I tried telnetting into the SMTP server

  1. I tried telnetting into smtpout.payserv.net port 25 and just got "220 *******************", then Putty 0.63 quit.

Is it possible my SMTP company has blocked my IP? Should I just call them?

Let's back up a bit

  1. I did 'netstat -an|grep smtp' and did not see an smtp service running. How do I start it?
  2. Do I need to add the smtp server to /etc/hosts?


2 Answers 2


You can use mail option from Linux command line. Default format is given below.

mail -s "Hello ASKUBUNTU" you@youremailid.com

To add content to the body of the mail while running the command you can use the following options. If you want to add text on your own:

echo "This will go into the body of the mail." | mail -s "Hello world" you@youremailid.com

And if you want mail to read the content from a file:

mail -s "Hello world" you@youremailid.com < /home/calvin/application.log

Some other useful options in the mail command are:

-s subject (The subject of the mail)

-c email-address (Mark a copy to this “email-address”, or CC)

-b email-address (Mark a blind carbon copy to this “email-address”, or BCC) Here’s how you might use these options:

echo "Welcome to the world of Calvin n Hobbes" | mail -s "Hello world" calvin@cnh.com -c hobbes@cnh.com -b susie.derkins@cnh.com

To add attachments u can use the -a option in mail

mail -a /path/to/file.to.attach -s "Hello ASKUBUNTU" you@youremailid.com 

Hope this helps.

  • Thank you. But I got an error: send-mail: Cannot open smtpout.secureserver.net:80 Can't send mail: sendmail process failed with error code 1
    – Bulrush
    Oct 22, 2014 at 16:14

Got it! In /etc/ssmtp/ssmtp.conf, the line "hostname=" should be my machine's name "ubuntucomp.net". That's all that was wrong.

However it does not send attachments. It seems other people have had the same problem: how to send an email with an attachment without installing an MTA. And I can't find a solution so far.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.