Can't send email via command line

I’m trying to setup automated emails via a bash script, and its not working. I can send emails to my personal email account through earthlink, but not my work email address. I have the script setup right now to use the mail command (just /bin/mail), and I believe its getting its settings from the yast module. Something to note, when I send an email the from address has the computer hostname attached. So if I sent an email from the root account it would be something like this: root@hostname.companyname.com. So I can get an email through to me@earthlink.net but not to me@companyname.com. I spoke with my IT guy and he said that the computer is trying to act like its own mail server and the proper server is blocking the incoming emails, as opposed to a client like Thunderbird which would send the email to the server and get routed from there.
I experimented with mutt, but I had the same symptoms.
Also, I tried using a few GUI tools like Thunderbird and claws-mail but what I found was that I could populate the email from the command line, but I still had to push the send button. The normal mail server is running Microsoft Exchange (2007?) and has SMTP enabled.
And I’m using 11.2. I know its old but I have to hold out till 13.1.
If anyone could point me in the right direction that would help. I know very little about email.
Thanks!

On 10/29/2013 03:26 PM, blank888 wrote:
>
> I’m trying to setup automated emails via a bash script, and its not
> working. I can send emails to my personal email account through
> earthlink, but not my work email address. I have the script setup right
> now to use the mail command (just /bin/mail), and I believe its getting
> its settings from the yast module. Something to note, when I send an
> email the from address has the computer hostname attached. So if I sent
> an email from the root account it would be something like this:
> root@hostname.companyname.com. So I can get an email through to
> me@earthlink.net but not to me@companyname.com. I spoke with my IT guy
> and he said that the computer is trying to act like its own mail server
> and the proper server is blocking the incoming emails, as opposed to a
> client like Thunderbird which would send the email to the server and get
> routed from there.

Your IT guy is likely correct. Most ISPs do not allow e-mail relaying
because of the propensity for that e-mail to be spam from bots. Most
users do not do crazy things like send e-mail directly from their own
servers, but instead login to a service online (Gmail, Earthlink, etc.)
with credentials and then send from there.

> I experimented with mutt, but I had the same symptoms.
> Also, I tried using a few GUI tools like Thunderbird and claws-mail but
> what I found was that I could populate the email from the command line,
> but I still had to push the send button. The normal mail server is
> running Microsoft Exchange (2007?) and has SMTP enabled.
> And I’m using 11.2. I know its old but I have to hold out till 13.1.
> If anyone could point me in the right direction that would help. I know
> very little about email.
> Thanks!

A quick way to confirm is to get a LAN trace from your system of TCP port
25 traffic when you do this. If you post the resulting capture file
somewhere we’ll probably be able to see the failure directly from the
target server.

Code:

sudo /usr/sbin/tcpdump -n -s 0 -i -w /tmp/smtp0.cap port 25
#run the command above, then in another shell run
#your mail commands, then stop the command above (Ctrl+c)
#and post the /tmp/smtp0.cap file


Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below…

Could you post your script?

On 2013-10-29 22:26, blank888 wrote:

> I spoke with my IT guy
> and he said that the computer is trying to act like its own mail server
> and the proper server is blocking the incoming emails, as opposed to a
> client like Thunderbird which would send the email to the server and get
> routed from there.

He is correct.

You have to configure mail or mutt to use an external smtp server, for
instance the one of your email address. You also have to configure it to
use your email address, not the system address. You have to read its manual.

Alternatively, you have to configure postfix to do that.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

On 2013-10-29, blank888 <blank888@no-mx.forums.opensuse.org> wrote:
> I experimented with mutt, but I had the same symptoms.

Mutt needs much more than just tinkering about with experimention to do the job. If you can send it from Thunderbird,
you can send it from mutt. You just need set your ~/.muttrc right to reflect the correct settings you have in
Thunderbird e.g.:


set smtp_url = "smtp://johndoe@imap.email.com:587/" # here 587 is the port address
set ssl_starttls = yes                              # or set to no
set from = "johndoe@email.com"
set realname = "John Doe"
set envelope_from = yes

If you find mutt too much (many do), you might want to try Alpine which has a much friendlier in-program configuration
interface. I prefer mutt because it’s the most flexible and configurable EUA I know and allows me to write emails in
Vim.

On 2013-10-29, blank888 <blank888@no-mx.forums.opensuse.org> wrote:
> I experimented with mutt, but I had the same symptoms.

Mutt needs much more than just tinkering about with experimention to do the job. If you can send it from Thunderbird,
you can send it from mutt. You just need set your ~/.muttrc settings correctly to reflect the working configuration you
have in Thunderbird e.g.:


set smtp_url = "smtp://johndoe@server.email.com:587/" # here 587 is the port
set ssl_starttls = yes                                # or set to no
set from = "johndoe@email.com"
set realname = "John Doe"
set envelope_from = yes

If you find mutt too much (many do), you might want to try Alpine which has a much friendlier in-program configuration
interface. I prefer mutt because it’s the most flexible and configurable EUA I know and allows me to write emails in
Vim.

On 2013-10-30 11:27, flymail wrote:
> If you find mutt too much (many do), you might want to try Alpine which has a much friendlier in-program configuration
> interface. I prefer mutt because it’s the most flexible and configurable EUA I know and allows me to write emails in
> Vim.

For just sending email from scripts, both are excessive. Mailx, which is
the current “mail” implementation can do it fine. You just have to read
the manual - ok, manuals are boring, but mutt and alpine are worse in
that respect :wink:


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

On 2013-10-30, Carlos E. R. <robin_listas@no-mx.forums.opensuse.org> wrote:
> On 2013-10-30 11:27, flymail wrote:
>> If you find mutt too much (many do), you might want to try Alpine which has a much friendlier in-program configuration
>> interface. I prefer mutt because it’s the most flexible and configurable EUA I know and allows me to write emails in
>> Vim.
>
> For just sending email from scripts, both are excessive. Mailx, which is
> the current “mail” implementation can do it fine. You just have to read
> the manual - ok, manuals are boring, but mutt and alpine are worse in
> that respect :wink:

I deleted my previous post because I noticed the OP was more interested in scripting email posts rather than having
difficulties using mutt to deliver individual emails. I know the former can be done and that this is very
straightforward using mutt but I’m not sufficiently familiar with the commands to offer properly informed advice.

On 2013-10-30 12:20, flymail wrote:

> I deleted my previous post

My system caches NNTP posts, so the delete does not reach me :frowning:


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

So after looking at the man page for mailx again, I saw that you can specify the smtp settings withing the command. I did actually look at the man page before, I guess I missed it. I feel kinda dumb.
Anyways, I’m trying to run

echo "test" | mailx -S from=me@company.com -S smtp=company.com:25 -S smtp-auth=login -S smtp-auth-user=me@company.com smtp-auth-password=mypass -S smtp-use-starttls -s "smtp test" me@earthlink.net

and it comes back with error “500 5.3.3 Unrecognized command”. I know the port number is right because if I run a port scan on the server I see port 25 open with STARTTLS running. If I eliminate the starttls option I get error “504 5.7.4 Unrecognized authentication type”.
I got a working configuration from a co-workers Thunderbird account and he is using STARTTLS with NTLM at the authentication method, and is using port 25.
Another interesting quirk. If I try to setup Thunderbird on this exact computer, it requires me to use no authentication for the smtp server. This could be due to a change in the rules my IT guy made while trying to get this to work, but I’m not sure. If I try to run

echo "test" | mailx -S from=me@company.com -S smtp=mail.company.com -s "smtp test" me@earthlink.net

I get error “550 5.7.1 Unable to relay”. This happens regardless of whether I specify the “from” attribute or the port number.
I think I’m making progress, but I’m not there yet.

The script itself is somewhat long and mundane. It just makes sure it has the latest copy of the code, then runs a make clean, runs some tests, and tries to run make. The command I am using for the actual email is

mail -s "$pass_subject" $email_address < $email_message

That is the actual line of code from the script. I use either a $pass_subject or a $fail_subject depending on whether the build passed or failed and the other variables are pretty self-explanatory. Relevant sections of the script output to $email_message so I have a central place for output to go and I use $email_address because there are a few different mail commands that all go to the same address. However if the mail command becomes very tedious I’ll change that to a function instead of a single command.

So everything is working now. It seems the command didn’t like me giving it the hostname instead of the IP address. The command that finally worked is:

mailx -S smtp=IPaddress -s $subject $email_address< $file

Thanks for your help!