View previous topic :: View next topic |
Author |
Message |
Unclethommy Guru
Joined: 24 Jul 2006 Posts: 407
|
Posted: Tue Mar 06, 2007 10:29 am Post subject: Sending mail via gmail/pop3 via command line? [solved] |
|
|
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 |
|
|
ashtophet Guru
Joined: 08 Aug 2004 Posts: 397
|
Posted: Tue Mar 06, 2007 3:27 pm Post subject: |
|
|
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 |
|
|
Unclethommy Guru
Joined: 24 Jul 2006 Posts: 407
|
Posted: Tue Mar 06, 2007 4:19 pm Post subject: |
|
|
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 |
|
|
ashtophet Guru
Joined: 08 Aug 2004 Posts: 397
|
|
Back to top |
|
|
Unclethommy Guru
Joined: 24 Jul 2006 Posts: 407
|
Posted: Wed Mar 07, 2007 10:06 am Post subject: |
|
|
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 |
|
|
ashtophet Guru
Joined: 08 Aug 2004 Posts: 397
|
Posted: Wed Mar 07, 2007 4:30 pm Post subject: |
|
|
Do you have PORT_LOG_DIR="/var/log/portage" set? |
|
Back to top |
|
|
Unclethommy Guru
Joined: 24 Jul 2006 Posts: 407
|
Posted: Thu Mar 08, 2007 11:05 am Post subject: |
|
|
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 |
|
|
ashtophet Guru
Joined: 08 Aug 2004 Posts: 397
|
Posted: Thu Mar 08, 2007 11:07 pm Post subject: |
|
|
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 |
|
|
Unclethommy Guru
Joined: 24 Jul 2006 Posts: 407
|
Posted: Fri Mar 09, 2007 10:34 am Post subject: |
|
|
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 |
|
|
ashtophet Guru
Joined: 08 Aug 2004 Posts: 397
|
Posted: Fri Mar 09, 2007 3:08 pm Post subject: |
|
|
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 |
|
|
Unclethommy Guru
Joined: 24 Jul 2006 Posts: 407
|
Posted: Fri Mar 09, 2007 3:55 pm Post subject: |
|
|
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 |
|
|
ashtophet Guru
Joined: 08 Aug 2004 Posts: 397
|
Posted: Fri Mar 09, 2007 6:30 pm Post subject: |
|
|
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 |
|
|
Unclethommy Guru
Joined: 24 Jul 2006 Posts: 407
|
Posted: Fri Mar 09, 2007 9:02 pm Post subject: |
|
|
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 |
|
|
|