You are not logged in.

#1 2010-05-27 19:34:18

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

sending email from the shell

I'd like to send trivial emails to my external email addy via POP3 (just text, no attachments) from the shell.  Is postfix my best bet?  Is there something lighter?  The postfix wiki page seems rather involved for what I want to do.

Thanks for the suggestions!

EDIT:  Found sendEmail which is pretty nice.  Other suggestions are still welcomed!

Last edited by graysky (2010-05-27 19:50:31)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2010-05-27 20:32:09

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: sending email from the shell

esmtp, msmtp, ssmtp

I suggest msmtp.

Offline

#3 2010-05-27 20:43:14

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: sending email from the shell

echo "message" | mailx -s subject me@domain.com

Offline

#4 2010-05-27 21:38:56

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: sending email from the shell

@karol

mailx doesn't have an MTA, does it?  What are you using to send the email?

Offline

#5 2010-05-27 22:18:01

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: sending email from the shell

> What are you using to send the email?
Good question. How can I find out?

[root@black pics]# pacman -Q esmtp msmtp ssmtp postfix
error: package "esmtp" not found
error: package "msmtp" not found
error: package "ssmtp" not found
error: package "postfix" not found
[root@black pics]# pacman -Q mailx
error: package "mailx" not found
[root@black pics]# pacman -Q mailx-heirloom
mailx-heirloom 12.4-3

.
http://bugs.archlinux.org/task/8834
It doesn't need an smtp server running on localhost but can connect to a smarthost, even with several encryption methods (SMTPS, SMTP+TLS, IMAP etc.). It also provides a basic MUA (which UNIX mailx does as well).

Last edited by karol (2010-05-27 22:21:48)

Offline

#6 2010-05-27 22:23:15

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: sending email from the shell

what does this point to:

ls -l /usr/sbin/sendmail

Offline

#7 2010-05-27 22:24:29

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: sending email from the shell

[karol@black ~]$ ls -l /usr/sbin/sendmail
lrwxrwxrwx 1 root root 14 Apr 17 19:16 /usr/sbin/sendmail -> /usr/bin/mailx

I was setting up rtorrent and found this http://wiki.archlinux.org/index.php/RTo … sing_GMail
I thought it was neat and now this is how I upload daily backups (they're tiny) to Gmail :-)

Last edited by karol (2010-05-27 22:30:03)

Offline

#8 2010-05-27 22:35:45

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: sending email from the shell

Install msmtp and make a basic config file in ~/.msmtprc, for example:

account        gmail
host           smtp.gmail.com
port           587
protocol       smtp
auth           on
from           graysky@gmail.com
user           graysky@gmail.com
password       password
tls            on
tls_starttls   on
tls_trust_file /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt

account default : gmail

Make sure no one else can read or write to that file ('chmod 600 ~/.msmtprc'). Then double-check that mailx is installed (it's in base) and add the following line to ~/.mailrc:

set sendmail="/usr/bin/msmtp"

Everythings all set up! Now just pipe your message to mailx, like karol mentioned earlier:

$ echo "message" | mail -s subject me@domain.com

Last edited by fflarex (2010-05-27 22:48:49)

Offline

#9 2010-05-27 22:44:05

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: sending email from the shell

etc/nail.rc

set smtp=smtp.gmail.com:587
set smtp-use-starttls
set ssl-verify=ignore
set ssl-auth=login
set smtp-auth-user=ME@gmail.com
set smtp-auth-password=YOURPASS

Offline

#10 2010-05-27 22:51:47

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: sending email from the shell

@graysky
Hmm cool.  It looks like mailx-heirloom has an MTA built in.  You can add it to the list I provided.

Offline

#11 2010-05-27 22:53:51

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: sending email from the shell

I'm not sure about the link '/usr/sbin/sendmail -> /usr/bin/mailx' I may have done it by hand but I honestly don't remember.

Offline

#12 2010-05-27 22:55:59

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: sending email from the shell

karol wrote:

I'm not sure about the link '/usr/sbin/sendmail -> /usr/bin/mailx' I may have done it by hand but I honestly don't remember.

No mailx-heirloom would have done it.  /usr/sbin/sendmail is a symlink to your MTA.

Offline

#13 2010-05-27 23:17:41

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: sending email from the shell

I don't want to go offtopic but it still concerns sending email from the shell so here goes.

I uninstalled mailx-heirloom and removed the (now broken) link. I reinstalled mailx-heirloom, changed /etc/nail.rc to the one I posted here but I couldn't send mail, because it complained about the lack of sendmail. After 'ln -s /usr/bin/mailx /usr/sbin/sendmail' the mails are send OK.

http://repos.archlinux.org/wsvn/communi … k/PKGBUILD
I don't see anything about setting a symlink to sendmail but I'm a noob so I may be wrong.

http://arm.konnichi.com/find/index.php? … 2Fsendmail
None of the apps providing sendmail is present on my system.

Offline

#14 2010-05-28 05:47:04

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: sending email from the shell

Thanks for all the suggestions, all. Look like I'll stick with sendEmail for my purposes.  I also wrote a companion script in the AUR called checkip.  The whole reason I wanted this ability was to have an email sent to me when the external IP addy changes (the email needs to contain the new IP).  Anyway, thanks again!

Last edited by graysky (2010-05-28 05:47:43)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#15 2010-05-28 12:43:29

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: sending email from the shell

I do something similar to dynamically update some IPtables rules.  I use this command to get the wan IP

curl -Ls http://tnx.nl/ip

Last edited by steve___ (2010-05-28 12:45:24)

Offline

Board footer

Powered by FluxBB