LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Command Line e-mail client w/Authentication Needed!! (http://www.linuxquestions.org/questions/linux-software-2/command-line-e-mail-client-w-authentication-needed-388811/)

rootking 12-02-2005 11:06 PM

Command Line e-mail client w/Authentication Needed!!
 
I have qwest DSL and when sending e-mail I must authenticate with the qwest SMTP e-mail server (pop.phnx.qwest.net). Anyways, the machine that will be sending this e-mail needs to do it over command line. Is there a way to include authentication credentials (user/pass) to login to the SMTP server using a command line mail client?

This is the error I recieve as root when sending an e-mail with this command:

mail -s Testing myemailaddress@gmail.com

Final-Recipient: RFC822; myemailaddress@gmail.com
Action: failed
Status: 5.1.3
Remote-MTA: DNS; pop.phnx.qwest.net
Diagnostic-Code: SMTP; 553 relaying denied.

I'm pretty sure that my issue is authentication. The qwest guy said you had to authenticate as well over SMTP.


thanks
rootking

vls 12-03-2005 05:18 AM

Try creating a .netrc file

netrc man page
for the format.

rootking 12-03-2005 12:51 PM

Quote:

Originally Posted by vls
Try creating a .netrc file

netrc man page
for the format.

thanks but this is used for FTP. I need an e-mail sent to me every day. I need the convenience of just checking my e-mail and seeing the message from the server, about it's status. This needs to be a cron job or something that can be scheduled to send out the e-mail message. Here is what I originally used and it worked. the problem is that SMTP authentication wasn't required.

Code:


#!/usr/local/bin/bash
echo "" > /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "RAID Status                          " >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "" >> /joelsrvinfo
/sbin/atacontrol status ar0 >> /joelsrvinfo

echo "" >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "Memory Status                          " >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "" >> /joelsrvinfo
/usr/local/bin/muse -m >> /joelsrvinfo

echo "" >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "Disk Space Status                    " >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "" >> /joelsrvinfo
/bin/df -h >> /joelsrvinfo

echo "" >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "Server Uptime                        " >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "" >> /joelsrvinfo
/usr/bin/uptime >> /joelsrvinfo
echo "" >> /joelsrvinfo
echo "" >> /joelsrvinfo


#####
###        Sending "Cat'ed" output to e-mail address

cat /joelsrvinfo | mail -s Joel_Server myemail@gmail.com
cd /etc/mail
make
newaliases
/etc/rc.d/sendmail restart

thanks

vls 12-03-2005 01:39 PM

Quote:

Originally Posted by rootking
thanks but this is used for FTP.
[big snip]
thanks

Actually, quite a few programs use the netrc file, fetchmail for one.
But the standard mail prog probably doesn't to think about it.

Try nail, it has command line authentication options. Nail is an enhanced version of the mail client.

Here's the nail man page

rootking 12-03-2005 06:17 PM

Quote:

Originally Posted by vls
Actually, quite a few programs use the netrc file, fetchmail for one.
But the standard mail prog probably doesn't to think about it.

Try nail, it has command line authentication options. Nail is an enhanced version of the mail client.

Here's the nail man page

Yeah, this is a great mail client. Here's what I have found. Qwest only requires pop authentication. What I did was setup an e-mail client using outlook where I entered all the username and password credentials (never touching the smtp authentication section) and I was able to send and receive just fine. After I had done that I ran this script on my BSD machine:

Code:



#!/usr/local/bin/bash
echo "" > /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "RAID Status                          " >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "" >> /joelsrvinfo
/sbin/atacontrol status ar0 >> /joelsrvinfo

echo "" >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "Memory Status                          " >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "" >> /joelsrvinfo
/usr/local/bin/muse -m >> /joelsrvinfo

echo "" >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "Disk Space Status                    " >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "" >> /joelsrvinfo
/bin/df -h >> /joelsrvinfo

echo "" >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "Server Uptime                        " >> /joelsrvinfo
echo "=====================================" >> /joelsrvinfo
echo "" >> /joelsrvinfo
/usr/bin/uptime >> /joelsrvinfo
echo "" >> /joelsrvinfo
echo "" >> /joelsrvinfo


#####
###    Sending "Cat'ed" output to e-mail address

cat /joelsrvinfo | nail -s "Joel Server Daily Status" -r Joel_BSD_Server myemail@gmail.com

Everything worked great and the e-mail with the "cat'ed" output of joelsrvinfo was sent to my e-mail address. As a side note, in ~/.mailrc I have an entry that looks like this:

Code:



set smtp=pop.phnx.qwest.net

nail references this specific user file for settings each time an e-mail is sent. Anyways, Then I went and had some lunch thinking all was well and I had finally figured this out. When I came back I ran the script again and started receiving an 553 Relay Denied Error. I couldn't get the e-mail to send out again. Come to find out, it seems that when the outlook client authenticated it lasted for around 5-10 minutes. After that I had to push the send/receive button within outlook to re-authenticate once again. Then I was once again able to send out e-mail from the BSD server.

So what I really need to do is authenticate to the pop server using the BSD machine before sending the e-mail using nail. This is where I am at now. If you can help me at all with this that would be great. I will be seeing what I can

thanks
rootking

vls 12-04-2005 12:13 PM

Quote:

Originally Posted by rootking
So what I really need to do is authenticate to the pop server using the BSD machine before sending the e-mail using nail. This is where I am at now. If you can help me at all with this that would be great. I will be seeing what I can

Did you try this command line example near the end of the nail man page?:

Code:

env MAILRC=/dev/null from=scriptreply@domain smtp=host \
          smtp-auth-user=login smtp-auth-password=secret \
          smtp-auth=login nail -n -s "subject" \
          recipient@domain < content_file

I tried it with my gmail account but it barfed on me about couldn't get some authentication certificate.

But it did work with another email account I have so give it a whirl.

Other than that, I don't know. Let me know if you get it working on the BSD end.

rootking 12-04-2005 05:47 PM

Quote:

Originally Posted by vls
Did you try this command line example near the end of the nail man page?:

Code:

env MAILRC=/dev/null from=scriptreply@domain smtp=host \
          smtp-auth-user=login smtp-auth-password=secret \
          smtp-auth=login nail -n -s "subject" \
          recipient@domain < content_file

I tried it with my gmail account but it barfed on me about couldn't get some authentication certificate.

But it did work with another email account I have so give it a whirl.

Other than that, I don't know. Let me know if you get it working on the BSD end.


Where did you place this code?:

Code:

env MAILRC=/dev/null from=scriptreply@domain smtp=host \
          smtp-auth-user=login smtp-auth-password=secret \
          smtp-auth=login nail -n -s "subject" \
          recipient@domain < content_file

I put mine in /usr/local/etc/nail.rc. I also tried it within the script I've shown above. neither one gave me luck. Where did you place the above code?

Code:

MAILRC=/dev/null nail -n
I put this in my script. it wasn't clear to me what specific files these lines of code go into.

rootking 12-04-2005 06:42 PM

Figured things out :)
 
Well I finally figured this out. I first want to say how much I appreciate your help. You have helped guide me in the right direction.

The solution ended up being quite easy (as things usually are when I can't find an answer @ first). Remember how I had said that qwest requires POP authentication before you can send or receive e-mail, And how it "caches" the user/pass credentials for a short period of time. I ended up downloading a small pop3 client for BSD/Linux called pop3check (http://pop3check.sourceforge.net/) and running this command within the script to authenticate to the qwest pop server before sending the server status e-mail:

Code:

popcheck -s pop.phnx.qwest.net -u <user@qwest.net> -p
<password>

This is exactly what I had been needing to finish this server status script.

thanks for all your help again.

vls 12-04-2005 07:00 PM

Cool, no problem. I learned some new things myself.

As for this:
Code:

env MAILRC=/dev/null from=scriptreply@domain smtp=host \
smtp-auth-user=login smtp-auth-password=secret \
smtp-auth=login nail -n -s "subject" \
recipient@domain < content_file

I typed it on the command line.

If I was going to use it on a regular basis, I'd put in a shell script, jazz it up bit.

Glad I was of some use.


All times are GMT -5. The time now is 02:59 PM.