wiki:Docs/825gen2/Dev/Networking/SendEmail

Version 5 (modified by Don Wilson, 9 months ago) ( diff )

--

Sending Email

The 825gen2 can send emails.

The sendmail and msmtp commands are included in our Yocto Linux build.

cd /home/root


Create the msmtp config file

nano ~/.msmtprc

defaults
tls on

account gmail
auth on
host smtp.gmail.com
port 587
user wilsonwareapps@gmail.com
from wilsonwareapps@gmail.com

account default : gmail

Google no longer allows applications to use regular Google login password. Create an app specific password in google web portal

Keep a record the generated password

ueut eapo jrqv eaid

Create an email

nano message.txt

From: wilsonwareapps@gmail.com
To: don@wilsonware.com
Subject: Test email from 825

Test 825ARM Variscite

123456
abc

Send the email

msmtp -t < message.txt
password for wilsonwareapps@gmail.com at smtp.gmail.com: 

Enter the app password

How to store password to not require password entry every time email is sent? (At first tried adding libsecret, but that seems to require gnome-keyring. I added that and a bunch of dependent packages were also added. The keychain seems to be active but msmtp was still prompting for password. Then I learned the password could be added to the config file which is much simpler. Removing gnome-keychain for now since it adds a lot of unnecessary things.)

Password can be added to config file such as:

nano ~/.msmtprc

defaults
tls on

account gmail
auth on
host smtp.gmail.com
port 587
user wilsonwareapps@gmail.com
from wilsonwareapps@gmail.com
password ueut eapo jrqv eaid

account default : gmail



root@imx8mq-var-dart:~# msmtp -t < message.txt

E-mail sent successfully with no prompt for password

This could be done from app code using a system call.

How to send file attachments?

msmtp does not have support for file attachments directly. The message must be encoded in mime format.

Update message.txt to add MIME encoding

nano message.txt

From: wilsonwareapps@gmail.com
To: dwilson@cardet.com
Subject: Test email from 825
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="MyBoundaryString"


--MyBoundaryString
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

This is a message.

--MyBoundaryString
Content-Type: text/plain; file="file123.txt"
Content-Disposition: attachment; filename="file123.txt"
Content-Transfer-Encoding: base64

Create attachment file

nano attachment.txt

This is an attachment
123456
abcdefg

Use base64 to convert the attachment to base64 encoding:

base64 attachment.txt > /tmp/attachment

Now pipe both files to the msmtp command

cat message.txt /tmp/attachment | msmtp -t

This successfully sends email with attachment

Attachments (2)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.