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