Changes between Version 3 and Version 4 of Docs/825gen2/Dev/Networking/SendEmail


Ignore:
Timestamp:
02/15/24 08:36:09 (9 months ago)
Author:
Don Wilson
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Docs/825gen2/Dev/Networking/SendEmail

    v3 v4  
    5959}}}
    6060
     61
     62Enter the app password
     63
     64How to store password to not require password entry every time email is sent?
     65(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.)
     66
     67Password can be added to config file such as:
     68
     69{{{
     70nano ~/.msmtprc
     71
     72defaults
     73tls on
     74
     75account gmail
     76auth on
     77host smtp.gmail.com
     78port 587
     79user wilsonwareapps@gmail.com
     80from wilsonwareapps@gmail.com
     81password ueut eapo jrqv eaid
     82
     83account default : gmail
     84
     85
     86
     87root@imx8mq-var-dart:~# msmtp -t < message.txt
     88}}}
     89
     90E-mail sent successfully with no prompt for password
     91
     92This could be done from app code using a system call.
     93
     94
     95How to send file attachments?
     96
     97msmtp does not have support for file attachments directly. The message must be encoded in mime format.
     98
     99Update message.txt to add MIME encoding
     100
     101{{{
     102nano message.txt
     103
     104From: wilsonwareapps@gmail.com
     105To: dwilson@cardet.com
     106Subject: Test email from 825
     107MIME-Version: 1.0
     108Content-Type: multipart/mixed; boundary="MyBoundaryString"
     109
     110
     111--MyBoundaryString
     112Content-Type: text/plain
     113Content-Transfer-Encoding: 7bit
     114
     115This is a message.
     116
     117--MyBoundaryString
     118Content-Type: text/plain; file="file123.txt"
     119Content-Disposition: attachment; filename="file123.txt"
     120Content-Transfer-Encoding: base64
     121
     122}}}
     123
     124
     125Create attachment file
     126
     127{{{
     128nano attachment.txt
     129
     130This is an attachment
     131123456
     132abcdefg
     133}}}
     134
     135Use base64 to convert the attachment to base64 encoding:
     136
     137{{{
     138base64 attachment.txt > /tmp/attachment
     139}}}
     140
     141Now pipe both files to the msmtp command
     142
     143{{{
     144cat message.txt /tmp/attachment | msmtp -t
     145}}}
     146
     147This successfully sends email with attachment
     148