mesmariusz
Posts: 57
Joined: Fri Feb 15, 2013 6:07 am

Sending e-mails via Raspbery

Fri Feb 15, 2013 6:26 am

Hello. I would like to send e-mails including log messages via Raspbery. Should I install local server or can I use external smtp or Imap server eg from Google ?

If it is important I have dynamic IP from my Internet supplier.

Thank you for all your feedback.

mesmariusz
Posts: 57
Joined: Fri Feb 15, 2013 6:07 am

Re: Sending e-mails via Raspbery

Fri Feb 15, 2013 7:32 pm

I found a few solutions. What do you think whih would be the best for Raspbery connected to network via dynamic IP internet provider?

http://mitchtech.net/connect-raspberry- ... tter-more/
http://www.goldenline.pl/forum/2902836/ ... weram-smtp
http://www.linuxjournal.com/content/sen ... ail-netcat

Sob
Posts: 10
Joined: Wed Jan 16, 2013 4:33 pm

Re: Sending e-mails via Raspbery

Fri Feb 15, 2013 10:10 pm

You can't install local mail server on dynamic address and set it for direct delivery to target domains. That worked fine fifteen years ago, but not any longer, because of antispam measures employed by target servers. You would have to set it to forward all mail to some "real" server where you have an account. And when you do that, you don't need anything as complex as full mail server.

You can either use some DIY "talk to mail server directly" method (your links #1 and #3) for individual things or use system-wide method (e.g. msmtp mentioned in link #2). Many programs use sendmail for sending mail and msmtp (msmtp-mta package for Raspbian) can pretend to be exactly that. So you configure it once and it will work for many programs without additional configuration (it will make e.g. php's mail() function work).

Example configuration file /etc/msmtprc:

Code: Select all

defaults
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
#tls_certcheck off
syslog LOG_MAIL

account default
host smtp.example.net
from youraccount@example.net
auth on
user yourlogin
password yourpassword
You might need to block tls_trust_file and unblock tls_certcheck if target server doesn't have valid certificate. All logs will go nicely to /var/log/mail.* files. And if you do it system-wide like this, don't give accounts on your RasPi to untrusted strangers, because they too could use sendmail with this account.

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: Sending e-mails via Raspbery

Fri Feb 15, 2013 10:33 pm

I have successfully used Python to send email using an external mail server (on my web hosting account).

The details are here:
http://www.raspberrypi-spy.co.uk/2012/0 ... ng-python/

My garage security system uses this mechanism to alert me when the doors are opened.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

mesmariusz
Posts: 57
Joined: Fri Feb 15, 2013 6:07 am

Re: Sending e-mails via Raspbery

Mon Feb 18, 2013 12:13 pm

... or use system-wide method (e.g. msmtp mentioned in link #2). Many programs use sendmail for sending mail and msmtp (msmtp-mta package for Raspbian) can pretend to be exactly that. So you configure it once and it will work for many programs without additional configuration (it will make e.g. php's mail() function work).
Ok, so this #2 method sims to be the best.
What do you think about using Python ?

Return to “Raspberry Pi OS”