打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

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

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:

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
在 Linux 命令行发送邮件的 5 种方法
批量发邮件方法
编写global.asax
index.aspx.cs 02/admin/登录模块
退出登录,清除Session
Ubuntu LightDM轻量级桌面显示管理器
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服