Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Sending mail via gmail/pop3 via command line? [solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
Unclethommy
Guru
Guru


Joined: 24 Jul 2006
Posts: 407

PostPosted: Tue Mar 06, 2007 10:29 am    Post subject: Sending mail via gmail/pop3 via command line? [solved] Reply with quote

Hi there, a very quick question:

I want to be able to run a command at the end of a long emerge to email my at my office to tell me its done so i can ssh into it and then shutdown if necessary. I was wondering what program would be best. I have read several posts which seem to recommend mailx but they seem to be for internal mailing or mailing from your own server(?) I am new to the mailing world and have got by by simply adding my gmail and pop3 into thunderbird. I was wondering if someone could steer me into the right directiong in sending mail from commandline through a pop3 account or gmail.

Thanking you in advance :)


Last edited by Unclethommy on Fri Mar 09, 2007 3:55 pm; edited 1 time in total
Back to top
View user's profile Send private message
ashtophet
Guru
Guru


Joined: 08 Aug 2004
Posts: 397

PostPosted: Tue Mar 06, 2007 3:27 pm    Post subject: Reply with quote

You could use msmtp (paludis -i msmtp || emerge -av msmtp) for that (assuming you want to use an external (gmail) smtp server.

It has a configuration file (typically $HOME/.msmtprc) on which you can add various accounts, then select any of them via msmtp -a account_name (so, for instance: msmtp -a gmail01 destination@mail < logfile).

Anyway via mailx you can send a mail from your box to anywhere in the world (I'm using this to get reports on weekly backups done by shell scripts [1].


-----------------------------------

[1] For instance, for backing up my documents I have:

Code:

#!/bin/sh

#backup dos documentos

scr_dir=/home/joham_luis/.scripts
dir=/home/joham_luis/documentos
back=/mnt/backup/documentos
log=/mnt/backup/documentos-$(date +%Y%m%d).log
mail=/mnt/backup/documents-$(date +%Y%m%d).mail

if cd $dir && rsync -avH --backup --backup-dir=$back * $back > $log;
then echo "Todo correu bem, segue o log"> $mail;cat $log>>$mail; mail -s "Backup documentos" mail@address <$mail
else echo "Houve algum problema, segue o log">$mail;cat $log>>$mail;mail -s "Backup documentos" mail@address <$mail
fi


P.S.: Also if you use portage, you can set:


PORTAGE_ELOG_CLASSES="warn error info log"
PORTAGE_ELOG_SYSTEM="save mail"
PORTAGE_ELOG_MAILURI="destination@address mailer" (where mailer may be, for instance /usr/sbin/sendmail)

on your make.conf, so automagically you can get email notification about your emerges. For more info check /etc/make.conf.example
Back to top
View user's profile Send private message
Unclethommy
Guru
Guru


Joined: 24 Jul 2006
Posts: 407

PostPosted: Tue Mar 06, 2007 4:19 pm    Post subject: Reply with quote

Great, i've just now got mail configured so when i type:

Code:
echo test | mail -s "testing ssmtp" -u user  user.name@domain


it sends a mail

how do i enter this into the portage code in make.conf?

I have the following in my make.conf

Code:
PORTAGE_ELOG_CLASSES="warn error log"
PORTAGE_ELOG_SYSTEM="save mail"
PORTAGE_ELOG_MAILURI="user.name@domain mail"
PORTAGE_ELOG_MAILFROM="emerge@heaven"
PORTAGE_ELOG_MAILSUBJECT="package \${PACKAGE} merged on \${HOST} with notice"


i have also tried
Code:

PORTAGE_ELOG_MAILURI="user.name@domain /usr/sbin/sendmail"


but i dont get any email :( do i need to include any option flags etc?
Back to top
View user's profile Send private message
ashtophet
Guru
Guru


Joined: 08 Aug 2004
Posts: 397

PostPosted: Tue Mar 06, 2007 6:37 pm    Post subject: Reply with quote

http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=3&chap=1#doc_chap4

I would try:

PORTAGE_ELOG_MAILURI="user@domain.com"

Or just the full user@domain.com username:password@smtp.some.domain:port_number"
Back to top
View user's profile Send private message
Unclethommy
Guru
Guru


Joined: 24 Jul 2006
Posts: 407

PostPosted: Wed Mar 07, 2007 10:06 am    Post subject: Reply with quote

no luck :( do i need to set a flag to send the log or is it on by default?

Code:
PORTAGE_ELOG_CLASSES="warn error log"
PORTAGE_ELOG_SYSTEM="save mail"
PORTAGE_ELOG_MAILURI="addressto.sendto@domain.ac.uk gmailuseraccount:password@smtp.gmail.com:587"
PORTAGE_ELOG_MAILFROM="emerge@heaven"
PORTAGE_ELOG_MAILSUBJECT="package \${PACKAGE} merged on \${HOST} with notice"
Back to top
View user's profile Send private message
ashtophet
Guru
Guru


Joined: 08 Aug 2004
Posts: 397

PostPosted: Wed Mar 07, 2007 4:30 pm    Post subject: Reply with quote

Do you have PORT_LOG_DIR="/var/log/portage" set?
Back to top
View user's profile Send private message
Unclethommy
Guru
Guru


Joined: 24 Jul 2006
Posts: 407

PostPosted: Thu Mar 08, 2007 11:05 am    Post subject: Reply with quote

Yup, I've added it, tried to emerge nano and didnt get an email :(

Do i need to put a $ in front of the variable PORT_LOG_DIR? Currently my make.conf reads:

Code:
# These settings were set by the catalyst build script that automatically built this stage
# Please consult /etc/make.conf.example for a more detailed example

CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium4 -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"


#CFLAGS="-O2 -mtune=i686 -pipe"
#CHOST="i686-pc-linux-gnu"
#CXXFLAGS="-O2 -mtune=i686 -pipe"
MAKEOPTS="-j2"
USE="-gtk -gnome -xmms mp3 v4l xvid nas qt mysql win32codecs asf opengl nvidia kde dvd alsa cdr samba ppds server"
FEATURES="-strict ccache"
CCACHE_DIR="/var/tmp/ccache/"
CCACHE_SIZE="2G"
VIDEO_CARDS="nvidia"
LIRC_DEVICES="leadtek_pvr2000"
PORTDIR_OVERLAY="/usr/local/portage"
source /usr/portage/local/layman/make.conf
PORT_LOG_DIR="/var/log/portage"
PORTAGE_ELOG_CLASSES="warn error log"
PORTAGE_ELOG_SYSTEM="save mail"
PORTAGE_ELOG_MAILURI="addresstosendto@domain usernameofaccounttosendfrom:password@smtp.gmail.com:587"
PORTAGE_ELOG_MAILFROM="emerge@heaven"
PORTAGE_ELOG_MAILSUBJECT="package \${PACKAGE} merged on \${HOST} with notice"
Back to top
View user's profile Send private message
ashtophet
Guru
Guru


Joined: 08 Aug 2004
Posts: 397

PostPosted: Thu Mar 08, 2007 11:07 pm    Post subject: Reply with quote

It seems ok for me.

(Note that I'm not using portage anymore) Try:

PORTAGE_ELOG_MAILURI="addresstosendto@domain /usr/sbin/sendmail"

Which MTA are you using? ssmtp maybe?
Back to top
View user's profile Send private message
Unclethommy
Guru
Guru


Joined: 24 Jul 2006
Posts: 407

PostPosted: Fri Mar 09, 2007 10:34 am    Post subject: Reply with quote

No luck I'm afraid, I tried the sendmail option and it didnt work :(

I have made changes to the /etc/ssmtp/ssmtp.conf folder which got the command line working. so i am guessing i am using ssmtp as my MTA?

When i need to send an email via command line i simply type

Code:
echo test | mail -s "testing ssmtp" -u user  address@domain.co.uk


Which works fine and send mail to the required address

EDIT: I just did an emerge world update and i got an email from portage about a warning!!!! I should be excited, but why doesnt it send me the usual logs too? I have set the log flag in the options so it should email me warning, errors and logs right?
Back to top
View user's profile Send private message
ashtophet
Guru
Guru


Joined: 08 Aug 2004
Posts: 397

PostPosted: Fri Mar 09, 2007 3:08 pm    Post subject: Reply with quote

OK, It seems you're almost there...

TFM wrote:

PORTAGE_ELOG_CLASSES: This is where you set what kinds of messages to be logged. You can use any space-separated combination of info, warn, error, and log.
info: Logs "einfo" messages printed by an ebuild
warn: Logs "ewarn" messages printed by an ebuild
error: Logs "eerror" messages printed by an ebuild
log: Logs the "elog" messages found in some ebuilds


Looks like you could try 'info'

HTH
Back to top
View user's profile Send private message
Unclethommy
Guru
Guru


Joined: 24 Jul 2006
Posts: 407

PostPosted: Fri Mar 09, 2007 3:55 pm    Post subject: Reply with quote

Yup, i think thats got it working, i left out info initialy as I thought it might give me uncessary information,

EDIT: hmmm, its still seems to only want to email when it had information to print, it doesnt email me when there was an error and emerging was stopped :(
Back to top
View user's profile Send private message
ashtophet
Guru
Guru


Joined: 08 Aug 2004
Posts: 397

PostPosted: Fri Mar 09, 2007 6:30 pm    Post subject: Reply with quote

With PORTAGE_ELOG_CLASSES="info warn error log" it should be ok... As you're using gmail, check spam folder http://gmail.com
Back to top
View user's profile Send private message
Unclethommy
Guru
Guru


Joined: 24 Jul 2006
Posts: 407

PostPosted: Fri Mar 09, 2007 9:02 pm    Post subject: Reply with quote

Checked my gamil, no spam. :( Ah well, cant be picky i guess, would have been cool to have it to tell me something's gone wrong. Thanks a lot for you help and patience ashtophet. Let me know if you have any other suggestions.

Thanks again.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum