element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Open Source Hardware
  • Technologies
  • More
Open Source Hardware
Forum Send Email in pcDuino by Script and Python
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Open Source Hardware to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 0 replies
  • Subscribers 315 subscribers
  • Views 224 views
  • Users 0 members are here
  • openhardware
  • python
  • script
  • pcduino
Related

Send Email in pcDuino by Script and Python

alvin_jin
alvin_jin over 12 years ago

In this post, we describe how to send email in pcDuino by script and Python.

First let us look at send email by script:

Install the packages:

 

1

 

2

3

 

$sudo apt-get install ssmtp

 

$sudo apt-get install mailutils

$sudo apt-get install mpack

Next we configure SSMTP:

 

1

 

 

$sudo nano /etc/ssmtp/ssmtp.conf

 

Now we edit the fields,

 

1

 

2

3

4

5

 

AuthUser=youruserid@gmail.com

 

AuthPass=userpass

FromLineOverride=YES

mailhub=smtp.gmail.com:587

UseSTARTTLS=YES

To send email, using:

 

1

 

 

$echo "sample text" | mail -s "Subject" username@domain.tld

 

If we want to send email with attachment,

 

1

 

 

$mpack -s "test" /home/pi/test/somefile.ext username@domain.tld

 

Now we begin to look at the Python script used to send email:

 

01

 

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

 

#!/usr/bin/python

 

#-*- coding: utf-8 -*-

import smtplib

 

server= 'smtp.gmail.com'

port = 587

 

sender = 'sender@gmail.com'

recipient = 'receiver@linksprite.com'

password='password'

subject = 'Greeting from pcDuino'

body = 'Welcome to pcDuino!'

 

"Sends an e-mail to the specified recipient."

 

body = "" + body + ""

 

headers = ["From: " + sender,

           "Subject: " + subject,

           "To: " + recipient,

           "MIME-Version: 1.0",

           "Content-Type: text/html"]

headers = "\r\n".join(headers)

 

session = smtplib.SMTP(server, port)

 

session.ehlo()

session.starttls()

session.ehlo

session.login(sender, password)

 

session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)

session.quit()

To run the code, copy the above code and save to reportbyemail.py do:

 

1

 

 

$python reportbyemail.py

 

We will then receive the email:

email

  • Sign in to reply
  • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube