HOWTO send email with your Raspberry Pi

This is for all discussions related to IT and technology. Hardware, software, programming, it all goes here.
Post Reply
Randall
Posts: 1616
Joined: Wed Nov 18, 2015 9:15 am
Species: Funambulus palmarum (Squirrel)
Region: Gauteng

HOWTO send email with your Raspberry Pi

#1

Post by Randall »

Been struggling to get this to work, but the solution is simple.

Step 1- Install sendemail

Code: Select all

sudo apt-get install sendemail
Step 2- When finished, confirm it is installed properly

Code: Select all

$sendEmail
It will give you a whole screen full of options

Step 3- Sending an email

Code: Select all

sendEmail -f myaddress@isp.net \
-t myfriend@isp.net \
-s relay.isp.net \
-u "Test email" \
-m "Hi , this is a test email."
-f = sender's email address (can be spoofed)
-t = destination email address (MUST be valid)
-s = outgoing relay, look this up, for Cell C this is mail.cmobile.co.za
-u = Subject line (all text MUST be in quotes i.e. "")
-m = message body (all text MUST be in quotes i.e. "")

As simple as that.
User avatar
Raven Song
Stealer of Time
Posts: 7039
Joined: Tue Apr 24, 2012 8:56 pm
Gender: Does it matter?
Sexual preference: Other
Species: Shapeshifting Anubian
Region: Other
Location: Londonium ONce more...
Contact:

Re: HOWTO send email with your Raspberry Pi

#2

Post by Raven Song »

I'd like you to know... you speak a whole new language to me and it's freaking cool...

If I had the patience I'd try to learn this...
Learn the rules like a pro, so you can break them like an artist. Pablo Picasso
Randall
Posts: 1616
Joined: Wed Nov 18, 2015 9:15 am
Species: Funambulus palmarum (Squirrel)
Region: Gauteng

Re: HOWTO send email with your Raspberry Pi

#3

Post by Randall »

There's nothing special here, this is all text entered in the Linux shell.
This can be made to work on any Linux system, and probably on OS X aswell.

The reason this is nifty is because you do not need to install an MTA such as sendmail/exim, which are usually difficult to configure. It just works without you having to fiddle with any MTA
Leeward
Recalcitrant Ruminant
Posts: 7036
Joined: Wed Mar 19, 2014 10:23 pm

Re: HOWTO send email with your Raspberry Pi

#4

Post by Leeward »

That's why I love Python. Everything works straight out of the box.
Randall
Posts: 1616
Joined: Wed Nov 18, 2015 9:15 am
Species: Funambulus palmarum (Squirrel)
Region: Gauteng

Re: HOWTO send email with your Raspberry Pi

#5

Post by Randall »

So since this works, I am just going to write a wrapper in C and feed it all the bits from the arguments passed....
User avatar
Raven Song
Stealer of Time
Posts: 7039
Joined: Tue Apr 24, 2012 8:56 pm
Gender: Does it matter?
Sexual preference: Other
Species: Shapeshifting Anubian
Region: Other
Location: Londonium ONce more...
Contact:

Re: HOWTO send email with your Raspberry Pi

#6

Post by Raven Song »

And more weird language and words...

You guys really do speak a whole new world sometimes :P

I have never met any rappers who did anything in C, be it major or minor :P (worst. music. joke. ever....)
Learn the rules like a pro, so you can break them like an artist. Pablo Picasso
User avatar
Rakuen Growlithe
Fire Puppy
Posts: 6718
Joined: Tue Apr 01, 2008 2:24 pm
Gender: Male
Sexual preference: Bi
Species: Growlithe (pokemon)
Region: Other
Location: Pretoria
Contact:

Re: HOWTO send email with your Raspberry Pi

#7

Post by Rakuen Growlithe »

Does that mean you can send email without an email account?
"If all mankind minus one, were of one opinion, and only one person were of the contrary opinion, mankind would be no more justified in silencing that one person, than he, if he had the power, would be justified in silencing mankind."
~John Stuart Mill~

“Give me the liberty to know, to utter, and to argue freely according to conscience, above all liberties.”
~John Milton~
Randall
Posts: 1616
Joined: Wed Nov 18, 2015 9:15 am
Species: Funambulus palmarum (Squirrel)
Region: Gauteng

Re: HOWTO send email with your Raspberry Pi

#8

Post by Randall »

Rakuen Growlithe wrote:Does that mean you can send email without an email account?
Correct, that is what I did. That is what was required of the project.

I also suspect this is how my NAS drive at home is doing it.
User avatar
Valerion
Alpha Wolf
Posts: 2803
Joined: Fri Apr 11, 2008 8:50 pm
Gender: Male
Sexual preference: Gay
Species: Werewolf
Region: Gauteng
Location: ::1
Contact:

Re: HOWTO send email with your Raspberry Pi

#9

Post by Valerion »

You need to specify a "from" address, but it doesn't strictly need to be valid. Email is the easiest thing in the world to spoof. However, anti-spam measures may catch the invalid ones.

I have recently started to implement SPF, DKIM and DMARC specifically to combat this. Which is when found out that Google gets spam from my personal domain from India.
Randall
Posts: 1616
Joined: Wed Nov 18, 2015 9:15 am
Species: Funambulus palmarum (Squirrel)
Region: Gauteng

Re: HOWTO send email with your Raspberry Pi

#10

Post by Randall »

Quite correct Valerion. Quite correct.

This is for internal use, so I don't stress, just happy it works.

Its actually part of a system that is going to help automate JUnit testing.
User avatar
Rakuen Growlithe
Fire Puppy
Posts: 6718
Joined: Tue Apr 01, 2008 2:24 pm
Gender: Male
Sexual preference: Bi
Species: Growlithe (pokemon)
Region: Other
Location: Pretoria
Contact:

Re: HOWTO send email with your Raspberry Pi

#11

Post by Rakuen Growlithe »

Out of curiosity, what makes an email address valid? Can you just give yourself one or does it need to be tied to a domain name?
"If all mankind minus one, were of one opinion, and only one person were of the contrary opinion, mankind would be no more justified in silencing that one person, than he, if he had the power, would be justified in silencing mankind."
~John Stuart Mill~

“Give me the liberty to know, to utter, and to argue freely according to conscience, above all liberties.”
~John Milton~
Randall
Posts: 1616
Joined: Wed Nov 18, 2015 9:15 am
Species: Funambulus palmarum (Squirrel)
Region: Gauteng

Re: HOWTO send email with your Raspberry Pi

#12

Post by Randall »

Rakuen Growlithe wrote:Out of curiosity, what makes an email address valid? Can you just give yourself one or does it need to be tied to a domain name?
If you are sending mail, this is where validity didn't count. However many mail servers now check that the domain at least is valid.

If you are receiving mail, your DNS zone file needs a MX record otherwise the internet doesn't know where to route the mail you intend to receive. So when you send a mail to your self-created mail server, you need to somehow bind it to the domain in question. For this reason, you need the MX field to be populated in your zone file.

This is why spam is so prolific. Due to the design, it is possible to spoof the sender field completely.
User avatar
Valerion
Alpha Wolf
Posts: 2803
Joined: Fri Apr 11, 2008 8:50 pm
Gender: Male
Sexual preference: Gay
Species: Werewolf
Region: Gauteng
Location: ::1
Contact:

Re: HOWTO send email with your Raspberry Pi

#13

Post by Valerion »

Rakuen Growlithe wrote:Out of curiosity, what makes an email address valid? Can you just give yourself one or does it need to be tied to a domain name?
Here's the canonical answer:

https://tools.ietf.org/html/rfc5322#section-3.4.1
An addr-spec is a specific Internet identifier that contains a locally interpreted string followed by the at-sign character ("@", ASCII value 64) followed by an Internet domain.
Post Reply