# Sending mail on command line.

## josh

I need a way to send mail from the command line to our company's mail server to be delivered. I'm assuming that this can be done since any mail client (pine,thunderbird,outlook) can do this. I just can't figure out the syntax.

The problem is that on our application servers there are cronjobs that kick out emails to customers using the machines local sendmail to send off the mail. Sometimes our customers mail servers will reject the emails because it can't identify the app server as being a valid originating mail server. Anything sent from our mail server never has a problem. So I'm thinking if I can change these crons to act as clients; delivering the mail to our mail server to be sent out from there, just as though I was using thunder bird, it would work. How can I accomplish this on the command line?

Thanks in advance!

----------

## msalerno

Why not have sendmail relay off of the other mail server?

----------

## josh

I'd love to. I just don't know how. And if it involves any changes on the mail server then I can't do it. Our mailserver admin is less than helpful. Even if I did all of the work. How would I go about doing that?

----------

## msalerno

If you install ssmtp on the system running the cron jobs, you can easily setup relaying.  If you are stuck on sendmail, read up on mail_hub

----------

## GenTimJS

pine is a terminal based mail sending client, you may be able to script it to send some stuff by CLI ?

----------

## msalerno

I know you can also do it with mutt i guess

echo hi | mutt msalerno@foo.bar

----------

## josh

Yes, I am stuck with sendmail. I wasn't able to find anything on mail_hub but it did lead me to sendmail.mc. And it was alot easier than I thought. I just added the line:

```
define(`SMART_HOST',`smtp.mymailserver.com')
```

And now I can get email on my personal email account which I couldn't before. This also saves alot hassle because there are numerous scripts and programs which just call sendmail. Now I don't need to change them.

Thanks for all the help and suggestions guys!

----------

## mlybarger

i'm trying to figure out command line emails atm.  i currently have qmail installed, and seems to be running. i can send an email out using:

```

echo "foo" | sendmail someone@somewhere.com

```

and the message arrives.   i'd like to learn how to send attachments as well.  it's particulary usefull for at work to be able to email someone quickly a config file or some such from one of the linux machines (though they're SUSE machines, it should be similar, no?)

----------

## msalerno

```
echo "My Xorg conf" | mutt -a /etc/X11/xorg.conf user@foo.bar
```

----------

## josh

I have a program that generates excel-spreadsheet reports and emails them a-la sendmail (actually its a symlink from sendmail to postfix):

```
uuencode 12345.xls report-200601.xls |sendmail someone@somewhere.com
```

But the mutt looks a bit easier.

----------

## toralf

 *josh wrote:*   

> I have a program that generates excel-spreadsheet reports and emails them a-la sendmail (actually its a symlink from sendmail to postfix):
> 
> ```
> uuencode 12345.xls report-200601.xls |sendmail someone@somewhere.com
> ```
> ...

 In which package is uuencde ?

----------

## josh

I actually downloaded it from source (from god-knows-where now) and installed it. I see there is a package called uudeview:

http://www.gentoo-portage.com/app-text/uudeview

Which may or maynot have uu{en,de}code. It does have "uu" which looks like it might do something.

----------

## josh

I actually installed it and took a look. It has uuenview and uudeview. uuenview can be dropped in place of uuencode in the above example. I don't know where I was getting just "uu" from.

----------

## toralf

 *josh wrote:*   

> I actually installed it and took a look. It has uuenview and uudeview. uuenview can be dropped in place of uuencode in the above example. I don't know where I was getting just "uu" from.

 Thanks, it works.

----------

