日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Send Email in pcDuino by Script and Python | pcDuino: mini PC+Arduino

 xiaofenglib 2013-08-22

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
34
#!/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

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多