I have tried at least 3 different methods of sending an email from my Pi gmail address, all without success.
Could someone please advise the easiest way to achieve this.
I would like to send plain text and also email with an attachment.
Re: Sending email from RPi
ssmtp package is the easiest way I know of ...
you only have to enter a valid smtp account information in the config file ...
you only have to enter a valid smtp account information in the config file ...
Re: Sending email from RPi
@fredoll
I have tried SMTP, without success so far.
Is SSMTP different?
One of the lines in one of the Programs that I was unsure about was:
smtp_user = ????
as I did not know what to enter after the =.
Any advice would be appreciated.
I have tried SMTP, without success so far.
Is SSMTP different?
One of the lines in one of the Programs that I was unsure about was:
smtp_user = ????
as I did not know what to enter after the =.
Any advice would be appreciated.
- DougieLawson
- Posts: 40594
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Sending email from RPi
sudo apt-get install postfix heirloom-mailx
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Re: Sending email from RPi
What 3 methods did you try? What were the exact symptoms? Any error messages?
Well, the Python docs https://docs.python.org/2/library/email-examples.html - looks pretty straightforward ...apart from the fact that you need an SMTP server to send through.
Then there is the Gmail variable... This one works perfectly for me (Python 2.7.9 in a Debian VirtualBox VM on a Windows laptop, from my own gmail to a friend's gmail - to my work email it does not seem to arrive but get's saved in my gmail sent folder...) http://www.nixtutor.com/linux/send-mail ... th-python/
Well, the Python docs https://docs.python.org/2/library/email-examples.html - looks pretty straightforward ...apart from the fact that you need an SMTP server to send through.
Then there is the Gmail variable... This one works perfectly for me (Python 2.7.9 in a Debian VirtualBox VM on a Windows laptop, from my own gmail to a friend's gmail - to my work email it does not seem to arrive but get's saved in my gmail sent folder...) http://www.nixtutor.com/linux/send-mail ... th-python/
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Re: Sending email from RPi
Have you already tried mutt? I'm doing exactly what you seem to need and it's working like a charm after setting it up properly.RDS wrote:I have tried at least 3 different methods of sending an email from my Pi gmail address, all without success.
Could someone please advise the easiest way to achieve this.
I would like to send plain text and also email with an attachment.
The 'secret' is that you need to run through the menu to get the certificates stored; after doing that it work unattended until the certificates expire. My command line for mailing an ebook as attachment looks like this:
Code: Select all
mutt me@kindle.com -a /ix2/ebook/EN/J/Jo\ Nesbo/Midnight\ Sun\ -\ Jo\ Nesbo.mobi < /dev/null
Goodluck!
/emgi
Re: Sending email from RPi
I have just checked on my Windows PC and found the following error message has been created against another gmail email address that I use.
Someone just tried to sign in to your Google Account xxxxxxx.xxxxxx@gmail.com from an app that doesn't meet modern security standards. (I have added the x's in place of actual email address, so it does appear that one of my tries may have produced something.
Someone just tried to sign in to your Google Account xxxxxxx.xxxxxx@gmail.com from an app that doesn't meet modern security standards. (I have added the x's in place of actual email address, so it does appear that one of my tries may have produced something.
Re: Sending email from RPi
Maybe there is a difference in the smtp lib security between versions.
Perhaps worth noting that I used my gmail full address as username and (obviously) my gmail password.
Perhaps worth noting that I used my gmail full address as username and (obviously) my gmail password.
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
-
- Posts: 256
- Joined: Thu May 17, 2012 1:25 am
- Location: SW Missouri Ozarks
- Contact: Website
Re: Sending email from RPi
I think Google recently change the way you authenticate 3rd party send mail functions. The new routines use "OAuth 2.0" or something.
It used to be dead simple but I recently tried using some code I'd written in perl and used previously but it didn't work, so I looked into it a bit and moved on. I will have to get back to it though so I'll keep an eye on this thread to either find or offer a solution. In then meantime you might find something useful here:
https://developers.google.com/gmail/api/downloads
It used to be dead simple but I recently tried using some code I'd written in perl and used previously but it didn't work, so I looked into it a bit and moved on. I will have to get back to it though so I'll keep an eye on this thread to either find or offer a solution. In then meantime you might find something useful here:
https://developers.google.com/gmail/api/downloads
- DougieLawson
- Posts: 40594
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Sending email from RPi
Here's a piece of Perl code that works with GMail.Needs sudo apt-get install libnet-smtps-perl to work.
Code: Select all
#!/usr/bin/perl
use Net::SMTPS;
use Authen::SASL;
my $mailargs = {
'Port' => 587,
'doSSL' => 'starttls',
'SSL_verify_mode' => 'SSL_VERIFY_NONE',
};
my $user = 'example@gmail.com';
my $pass = 'mySecretRedactedPassword';
my $smtp = Net::SMTPS->new('smtp.gmail.com', %$mailargs);
my $sasl = Authen::SASL->new(
'mechanisms' => 'Digest-MD5',
'callback' => { 'user' => $user, 'pass' => $pass, 'authname' => $user}
);
$smtp->auth($sasl);
$smtp->mail('example@gmail.com');
$smtp->to('example@uk2.net');
$smtp->data;
$smtp->datasend('Hello from perl on a RaspberryPi');
$smtp->dataend;
$smtp->quit;
1;
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Re: Sending email from RPi
@DougieLawson
I was really hopeful there for a short while!
I didn't realise that Perl was a different language until I noticed that I didn't recognise any of the details of the code.
Unfortunately, it needs to be in Python to work with the application I have in mind.
Thanks anyway.
I was really hopeful there for a short while!
I didn't realise that Perl was a different language until I noticed that I didn't recognise any of the details of the code.
Unfortunately, it needs to be in Python to work with the application I have in mind.
Thanks anyway.
Re: Sending email from RPi
Sorry, I do not understand this at all.DougieLawson wrote:sudo apt-get install postfix heirloom-mailx
Re: Sending email from RPi
@emgi
I am not doing very well with understanding some of the replies that you guys have kindly put together for me.
What is mutt?
I am not doing very well with understanding some of the replies that you guys have kindly put together for me.
What is mutt?
- DougieLawson
- Posts: 40594
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Sending email from RPi
Sending email in python is equally trivial.
Mutt is a command line mail program, I prefer alpine (a clone of pine).
Code: Select all
#!/usr/bin/python3
import time
from datetime import datetime
import smtplib
# from email.mime.image import MIMEImage
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
f_time = datetime.now().strftime('%a %d %b @ %H:%M')
toaddr = 'example@uk2.net'
me = 'example@gmail.com'
password = 'mySecretRedactedPassword'
subject = 'Test message ' + f_time
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = me
msg['To'] = toaddr
msg.preamble = "Test message @ " + f_time
message = "Main body text here"
html = "<html><head></head><body><h1>Title</h1><p>Main text</body></html>"
plainText = MIMEText(message, 'plain')
htmlText = MIMEText(html,'html')
msg.attach(plainText)
msg.attach(htmlText)
try:
s = smtplib.SMTP('smtp.gmail.com',587)
# s.set_debuglevel(True)
s.starttls()
s.login(me,password)
s.send_message(msg)
s.quit()
except:
print ("Error: unable to send email")
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
- DougieLawson
- Posts: 40594
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Sending email from RPi
Open an LXTerminal, type in the command starting sudo ...RDS wrote:Sorry, I do not understand this at all.DougieLawson wrote:sudo apt-get install postfix heirloom-mailx
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
-
- Posts: 256
- Joined: Thu May 17, 2012 1:25 am
- Location: SW Missouri Ozarks
- Contact: Website
Re: Sending email from RPi
Thank you!DougieLawson wrote:Here's a piece of Perl code that works with GMail. ... Needs sudo apt-get install libnet-smtps-perl to work.
I'll have to play with that.
Re: Sending email from RPi
DougieLawson's examples in Perl and Python are essentially the same as the example I linked to (with the exception of the Python one sending MIME multipart - not just plain text email).
To verify I have just tried the same as yesterday in the VM now on Python 2.7.3 on a Windows 7 laptop and it works fine (at least between two gmail accounts).
Just to highlight some bits:
Also confirmed that sending the email worked to my work email too - the message just got blocked by the company email security software (possibly due to missing subject and maybe some other headers).
To verify I have just tried the same as yesterday in the VM now on Python 2.7.3 on a Windows 7 laptop and it works fine (at least between two gmail accounts).
Just to highlight some bits:
Code: Select all
import smtplib
# Using my own gmail address as sender
fromaddr = '...@gmail.com'
# Recipient(s) (in my test different from sender)
toaddrs = '...@gmail.com'
# The email message 'body'
msg = 'Testing python smtplib!'
# Credentials to log in to gmail
# Full gmail email address - same as sender
username = fromaddr
# The password I use to login to gmail interactively (obviously)
password = '...'
# The actual mail send
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
Last edited by -rst- on Tue Nov 17, 2015 10:08 am, edited 1 time in total.
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Re: Sending email from RPi
I guess we may have more and more Raspberry Pi users who are not necessarily admin users. If this is not the case with RDS the commands 'sudo' and 'apt-get' are something worth learning about.DougieLawson wrote:Open an LXTerminal, type in the command starting sudo ...RDS wrote:Sorry, I do not understand this at all.DougieLawson wrote:sudo apt-get install postfix heirloom-mailx
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
- DougieLawson
- Posts: 40594
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Sending email from RPi
I suspect that's one of the reasons why the (now very dead) PiStore experiment was started it gave the non-admin users a GUI way to install ready to run software without needing to know diddly squat about how their system works.-rst- wrote:I guess we may have more and more Raspberry Pi users who are not necessarily admin users. If this is not the case with RDS the commands 'sudo' and 'apt-get' are something worth learning about.
Replacing that with synaptic isn't an ideal solution, but at least it's got the GUI eye candy.
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
- elParaguayo
- Posts: 1943
- Joined: Wed May 16, 2012 12:46 pm
- Location: London, UK
Re: Sending email from RPi
I've used SMTP in python with gmail. If you go this way, I think you have to enable "access for less secure apps".
See here: https://support.google.com/accounts/ans ... 0255?hl=en
See here: https://support.google.com/accounts/ans ... 0255?hl=en
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.
Re: Sending email from RPi
Good to know. For some reason (maybe I just don't remember changing it for some earlier testing) mine was set to 'on'. Turning this to 'off caused the above code to fail with:elParaguayo wrote:I've used SMTP in python with gmail. If you go this way, I think you have to enable "access for less secure apps".
See here: https://support.google.com/accounts/ans ... 0255?hl=en
Code: Select all
smtplib.SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/ContinueSignIn?s...> Please
log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 z66sm10306337wmz.7 - gsmtp')
Tried also the Perl version courtesy of DougieLawson: (obviously) the same 'Access for less secure apps' needed for it to work.
Last edited by -rst- on Tue Nov 17, 2015 12:06 pm, edited 1 time in total.
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
- DougieLawson
- Posts: 40594
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Sending email from RPi
My sample code works without setting that. But it needs my regular very secure Google password.elParaguayo wrote:see here: https://support.google.com/accounts/ans ... 0255?hl=en
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Re: Sending email from RPi
Are you absolutely sure? I am getting the same SMTPAuthenticationError with your Python code and Perl code does nothing if I turn off the less secure apps. Both work if I turn the setting on. This is on a Debian (VirtualBox) VM.DougieLawson wrote:My sample code works without setting that. But it needs my regular very secure Google password.elParaguayo wrote:see here: https://support.google.com/accounts/ans ... 0255?hl=en
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
- DougieLawson
- Posts: 40594
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Sending email from RPi
Just checked and "Allow less secure apps: ON" is set.
Last edited by DougieLawson on Tue Nov 17, 2015 12:57 pm, edited 1 time in total.
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Re: Sending email from RPi
Hmm, interesting... I copied your code, just replaced the email addresses and the password - with the setting 'on' the code works fine - with 'off' it does not. What else (other than the OS we run the code in) could be different?
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'