RussoNC
Posts: 48
Joined: Fri Sep 07, 2012 6:53 am
Location: New Caledonia
Contact: Website

Sending mails with the Raspi

Wed Jan 02, 2013 1:41 am

Hello and Happy new year !
I searched for this subject in the forum (In google too, of course) but al the solutions that I was able to find do not explains how this works, well It did'nt work until now for me xD (Like postfix, heirloom-mailx)
I don't understand how this works.
There is no way to configure and install our own Raspberry SMTP server? (I don't know if this is possible) I'm pretty new in Linux Systems.
If someone can help me by a link or explaind me how to configure my raspi so I can be able to send mails (receive's not really usefull for the use I will give it) that will be just great.

Thanks you in advance!!
Whant to see MySQL, nginx in action on the Raspberry pi ? Check my site: www.pirepository.com

User avatar
.not
Posts: 17
Joined: Wed Aug 01, 2012 8:33 pm
Location: /dev/at
Contact: Website

Re: Sending mails with the Raspi

Wed Jan 02, 2013 7:50 am

Running a mailserver as a beginner? Not always the best choice.

Debian comes with the Exim4 MTA pre-installed, so in order to be able to send out mails you just have to run dpkg-reconfigure exim4-config with administrative rights and answer all the questions ask. That's it, you have now a send-only installation of Exim4. (Just a quick sidenote: If you are sitting behind a NAT'ed connection - for example DSL at home - you should use another mailserver a smarthost because many mailservers on the world wide web are configured to dismiss mails coming from a dynamic IP. By using a smarthost you can avoid this problem easily.)
| Debian, FreeBSD | Raspberry Pi, Model B, 512MB RAM |

RussoNC
Posts: 48
Joined: Fri Sep 07, 2012 6:53 am
Location: New Caledonia
Contact: Website

Re: Sending mails with the Raspi

Wed Jan 02, 2013 9:59 am

It's weird but I don't have Exim installed (or I did something wrong when I was experimenting with the raspi) I'll try to install it and do that you says. Thank you for the answer!
Whant to see MySQL, nginx in action on the Raspberry pi ? Check my site: www.pirepository.com

Borner
Posts: 49
Joined: Tue Sep 25, 2012 2:53 pm
Location: .de

Re: Sending mails with the Raspi

Sun Jan 13, 2013 9:02 pm

Hi,

I have the same question: trying to send mails from R-Pi.
So I'm looking for the right, light MTA.

Is there an MTA pre-installed on raspian OS?

Because I'm online with an DSL connection with dynamic IP, i like to connect my MTA to my mail account on an global mail provieder.
So the MTA should not send the mails into the world. The MTA have to use my existing mail accound. I know, this is possible with postfix. But is postfix the right MTA?
Or is DMA, exim4, ... the better way?

I don't need an powerful sendmailer. I simply need an existing sendmail command so that existing PHP script can use that command to send mails, triggert by an web page.

So what would be the best (small) MTA for the R-PI??

Borner.

Borner
Posts: 49
Joined: Tue Sep 25, 2012 2:53 pm
Location: .de

Re: Sending mails with the Raspi

Thu Jan 17, 2013 12:29 pm

No idea and no best practice tips from someone?

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: Sending mails with the Raspi

Thu Jan 17, 2013 1:38 pm

I have not done this with a RPi but I have done this with a Ubuntu Server there is a block set up by ISP's that stops mail comming from a dynamic IP as a anti-spam issue.

I use postfix to forward email from a PHP dynamic webpage to a webmail address.

It is fairly easy to sort your ISP will have a SMTP and you set up a thing called "relayhost" there's probably a help page about it in the FAQ's on your ISP webpage.

In Ubuntu using postfix this is one of the settings to be found in /etc/postfix/main.cf ;)

I am not saying this is definatly where your problem lies it's just one of the posibilities.

Also there's some conflict with Sendmail and Postfix I think it is just two pieces of software fighting for the same job.

Ubuntu is in the Debian family just like Raspbian so it should be similar
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

Borner
Posts: 49
Joined: Tue Sep 25, 2012 2:53 pm
Location: .de

Re: Sending mails with the Raspi

Thu Jan 17, 2013 2:41 pm

Thank you, for sharing your practice.

> is a block set up by ISP's that stops mail comming from a dynamic IP as a anti-spam issue.

i know. therefore i like to setup an MTA to work like mail client in order to use a global mail provider like gmail to send mails.
The MTA should connect to the email provider using my personal credentials to send the mails using my gmail account.

But i don't know, any good tutorial to set up something like that.

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: Sending mails with the Raspi

Thu Jan 17, 2013 2:45 pm

I do not know of one I beat my head against Google for three days just to crack the postfix, sendmail, and relayhost issues. But those keywords helped, Knowing that I needed to change the content of /etc/postfix/mail.cf was also a big help. ;)
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

jdc
Posts: 6
Joined: Thu Jan 10, 2013 2:25 pm
Location: Maidenhead UK

Re: Sending mails with the Raspi

Fri Jan 18, 2013 11:18 am

This is one of the examples I'm going to try this weekend

http://www.sbprojects.com/projects/rasp ... /exim4.php

jdc

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: Sending mails with the Raspi

Fri Jan 18, 2013 1:25 pm

be sure to let us know how you get on with this. ;)
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

towolf
Posts: 421
Joined: Fri Jan 18, 2013 2:11 pm

Re: Sending mails with the Raspi

Fri Jan 18, 2013 2:15 pm

To send myself email from under-the-bed server I use ssmtp. It’s the thinnest email sending solution I found on Debian. I use Gmail’s smtp for this. It basically directly passes the emails on to Gmail.

config file:

Code: Select all

$ cat /etc/ssmtp/ssmtp.conf 
AuthUser=<username>@gmail.com
AuthPass=<password>
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
hostname=whatever.example.com
mailhub=smtp.gmail.com:587
root=<username>@gmail.com

jdc
Posts: 6
Joined: Thu Jan 10, 2013 2:25 pm
Location: Maidenhead UK

Re: Sending mails with the Raspi

Fri Jan 18, 2013 6:07 pm

exim4 results from testing this example http://www.sbprojects.com/projects/rasp ... /exim4.php

I use "X-Terminal as root" so I don't have to keep typing sudo (your decision)

#apt-get install exim4
failed with unmet dependencies etc

unmet dependencies then surrgested trying
#apt-get -f install

this installed "libnet-ssleay-perl"

this time
#apt-get install exim4
worked fine

I follwed the rest of the instructions and everything works
There was one error message "paniclog has no-zero size" does not seem to make a difference and I've not checked why yet.

emailing via root@localhost does not work for me
but emailing directly
#mail -s "test subject line" jdc@gmail.com
works fine (jdc@gmail.com is not my real address :-) )

#mail -s "test subject line" jdc@gmail.com < test.txt
add's the contents of the text file as the main body of the email
This is great for putting any information in a txt file first then you only need a one liner for the email.

Also ran this line from a bash script and that also works.

jdc

thanks to
San Bergmans, Oisterwijk, The Netherlands
http://www.sbprojects.com
for the Howto

RonN
Posts: 2
Joined: Sat Nov 24, 2012 11:50 pm

Re: Sending mails with the Raspi

Sat Jan 19, 2013 1:23 am

The method that works for me is to use the ssmtp library, a standard debian package, used by the following python code:

______________________________________________

Code: Select all

import sys
import os
import traceback
import threading

def usage():
	print 'Command argument format for sending an email:'
	print '  $ send-mail <email-file>'
	print 'Where: <email-file> is the file containing the email to be send,'
	print '   including the To, From, and subject lines, followed by the'
	print '   email text body.'

def main():
	if len(sys.argv) <> 2:
		usage()
		sys.exit(1)

	fname = sys.argv[1]		# the name of the email file
	# first, extract the email destination address
	f = open(fname, 'rb')
	line1 = f.readline().strip()	# get the To address
	f.close()
	tk = line1.split(':')
	if len(tk) <> 2:
		print 'Error: The To line of the email file is corrupted'
		sys.exit(1)
	if tk[0].lower() <> 'to':
		print 'Error: The destination email address must be in the first line'
		sys.exit(1)

	to = tk[1].strip()
	print 'To: %s' % to
	os.system('cat '+fname+' | /usr/sbin/ssmtp '+to)
	sys.exit(0)

# setup and run app
if __name__=='__main__':
   main()
______________________________________________
(I hope the indentations dont get mangled on upload)

I configured the /etc/ssmtp/ssmtp.conf file like towolf (Fri Jan 18 2013) did, except I added one more line: AuthMethod=LOGIN near the beginning.

The program (and ssmtp) use an input file that looks like this:

Code: Select all

To:toname@toemailhost
From:fromname@frmemailhost
Subject:subject line for email
text of the email
goes here,
blah blah blah

RussoNC
Posts: 48
Joined: Fri Sep 07, 2012 6:53 am
Location: New Caledonia
Contact: Website

Re: Sending mails with the Raspi

Sat Jan 19, 2013 2:11 am

Thank you all of you guys, I think we don't have one but 2 or 3 solutions for this "problem" I'll check one by one when I will able to find some free time.
Thank you again and see you soon !
Whant to see MySQL, nginx in action on the Raspberry pi ? Check my site: www.pirepository.com

AndrewdAzotus
Posts: 83
Joined: Wed Feb 06, 2013 3:07 pm
Location: Canada

Re: Sending mails with the Raspi

Wed Feb 13, 2013 9:46 pm

how do I configure sSMTP not to use GMail but to use an SMTP server without auth, i.e. port 25?

I'm still getting emails from 'root'

my ssmtp.conf:

Code: Select all

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=

# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
#mailhub=mail
mailhub=smtp.eastlink.ca:25

# Where will the mail seem to come from?
rewriteDomain=

# The full hostname
hostname=raspberry.spi

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=NO
#YES
if I specify FromLineOverride=YES
I get a 550 5.1.0 error root@raspberrypi invalid mailer domain

my revaliases has one line;

Code: Select all

root:<myname>@<mydomain>.co.uk:smtp.eastlink.ca

User avatar
RTL
Posts: 30
Joined: Tue Jan 15, 2013 6:05 pm
Location: California
Contact: Website

Re: Sending mails with the Raspi

Fri Feb 15, 2013 12:38 am

You can probably setup a PHP script to send via Mandrill. It's free as long as you send less than 12,000 emails a month. http://mandrill.com/

Return to “Networking and servers”