{"id":27765,"date":"2020-10-15T11:32:58","date_gmt":"2020-10-15T09:32:58","guid":{"rendered":"https:\/\/pi3g.com\/?p=27765"},"modified":"2020-10-15T11:32:58","modified_gmt":"2020-10-15T09:32:58","slug":"gmail-workspace-gmail-suite-send-e-mail-from-server-using-msmtp","status":"publish","type":"post","link":"https:\/\/pi3g.com\/de\/gmail-workspace-gmail-suite-send-e-mail-from-server-using-msmtp\/","title":{"rendered":"Gmail Workspace \/ Gmail Suite e-Mail vom Server mit msmtp senden"},"content":{"rendered":"<p>We are in the process of migrating to Gmail, to be able to delegate managing a mail server.<\/p>\n<p>We used ssmtp on our server to email mails before, using our own mail server (Zimbra).<\/p>\n<p>I have now managed to get Gmail Workspace working, and would like to share some pointers on how to do that. <\/p>\n<p>This is done on a Debian \/ Ubuntu system.<\/p>\n<h1>Set up 2 factor authentication<\/h1>\n<p>Login to your Google account:<\/p>\n<p><a title=\"https:\/\/myaccount.google.com\/\" href=\"https:\/\/myaccount.google.com\/\">https:\/\/myaccount.google.com\/<\/a><\/p>\n<p>Click on the Security tab and scroll down to 2-step Verification, enable it.<\/p>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image-61.png\"><img loading=\"lazy\" decoding=\"async\" width=\"585\" height=\"169\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image_thumb-60.png\" border=\"0\"><\/a><\/p>\n<p>You will probably need to provide your mobile phone number to Google or choose another option here.<\/p>\n<h1>Set up an App password<\/h1>\n<p>Click on \u201cApp passwords\u201d below the 2-Step Verification.<\/p>\n<p>Google will require you to sign-in again.<\/p>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image-62.png\"><img loading=\"lazy\" decoding=\"async\" width=\"584\" height=\"429\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image_thumb-61.png\" border=\"0\"><\/a><\/p>\n<p>(Note I already have an app password set up, your screen might look a bit different in the beginning)<\/p>\n<p>Click on Select app, and select Other (custom name)<\/p>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image-63.png\"><img loading=\"lazy\" decoding=\"async\" width=\"364\" height=\"235\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image_thumb-62.png\" border=\"0\"><\/a><\/p>\n<p>You can enter any name you like \u2013 it is for your reference. For example, <\/p>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image-64.png\"><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"145\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image_thumb-63.png\" border=\"0\"><\/a><\/p>\n<p>Click on <strong>Generate<\/strong><\/p>\n<p>A popup window will appear. Your app password will be shown only this one time, so be sure to copy it.<\/p>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image-65.png\"><img loading=\"lazy\" decoding=\"async\" width=\"585\" height=\"423\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image_thumb-64.png\" border=\"0\"><\/a><\/p>\n<p>Note that the password is just shown as four segments of four characters each to be easier to read, <strong>there will be no spaces <\/strong>in the actual password.<\/p>\n<p>In this case the password is <\/p>\n<p><em>lwsznhkychasbbrh<\/em><\/p>\n<p>Click on Done.<\/p>\n<h1>Switch to msmtp<\/h1>\n<p>ssmtp is not maintained anymore, and will also possibly have issues connecting to Gmail:<\/p>\n<p><em>\/var\/log\/syslog:Oct 15 09:52:22 Athena sSMTP[19076]: SSL connection using ECDHE_ECDSA_CHACHA20_POLY1305<br \/>\n\/var\/log\/syslog:Oct 15 09:52:22 Athena sSMTP[19076]: Authorization failed (535 5.7.8&nbsp; <\/em><a href=\"https:\/\/support.google.com\/mail\/?p=BadCredentials\"><em>https:\/\/support.google.com\/mail\/?p=BadCredentials<\/em><\/a><em> ************.79 &#8211; gsmtp)<\/em><\/p>\n<p><em>ssmtp: Authorization failed (535 5.7.8&nbsp; <\/em><a href=\"https:\/\/support.google.com\/mail\/?p=BadCredentials\"><em>https:\/\/support.google.com\/mail\/?p=BadCredentials<\/em><\/a><em> *************.4 &#8211; gsmtp)<\/em><\/p>\n<p>Apparently the ECDHE auth part <a href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?f=28&amp;t=244147\">might be a problem for some users on newer systems<\/a>.<\/p>\n<p>The workaround is to switch to <strong>msmtp<\/strong>.<\/p>\n<p>Remove ssmtp (all commands run as root)<\/p>\n<blockquote>\n<p>apt-get purge ssmtp<\/p>\n<\/blockquote>\n<p>Install msmtp<\/p>\n<blockquote>\n<p>apt-get install msmtp msmtp-mta<\/p>\n<\/blockquote>\n<h1>Set up msmtp<\/h1>\n<blockquote>\n<p>nano \/etc\/msmtprc<\/p>\n<\/blockquote>\n<p>Put in the following data:<\/p>\n<blockquote>\n<p>defaults<br \/>\nauth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; on<br \/>\ntls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; on<br \/>\ntls_starttls&nbsp;&nbsp; on<br \/>\ntls_trust_file \/etc\/ssl\/certs\/ca-certificates.crt<br \/>\nlogfile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/var\/log\/msmtp.log<\/p>\n<p>account&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gmail<br \/>\nhost&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; smtp.gmail.com<br \/>\nport&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 587<\/p>\n<p>from&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user@example.com<br \/>\nuser&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user@example.com<br \/>\npassword&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lwsznhkychasbbrh<\/p>\n<p>account default : gmail\n<\/p>\n<p><\/p>\n<\/blockquote>\n<p>Change your login data (from, user, and password \u2013 I have taken <em>lwsznhkychasbbrh <\/em>from the example above).<\/p>\n<p>Note that you do not need to restart a service or anything like that \u2013 the access data will be used for the next email the server tries to send.<\/p>\n<p>Use the <strong>app password <\/strong>generated above \u2013 your account password will not work:<\/p>\n<p><em>msmtp: authentication failed (method PLAIN)<br \/>\nmsmtp: server message: 534-5.7.9 Application-specific password required. Learn more at<br \/>\nmsmtp: server message: 534 5.7.9&nbsp; <\/em><a href=\"https:\/\/support.google.com\/mail\/?p=InvalidSecondFactor\"><em>https:\/\/support.google.com\/mail\/?p=InvalidSecondFactor<\/em><\/a><em> *************.29 &#8211; gsmtp<br \/>\nmsmtp: could not send mail (account default from \/etc\/msmtprc)<\/em>\n<\/p>\n<p>Also, please note that the app password should be entered without spaces between the characters (as discussed above)<\/p>\n<p>Secure this file (it contains login data!):<\/p>\n<blockquote>\n<p>chmod 600 \/etc\/msmtprc<\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image-66.png\"><img loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"55\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image_thumb-65.png\" border=\"0\"><\/a><\/p>\n<h1>Enable Less secure apps<\/h1>\n<p><a title=\"https:\/\/admin.google.com\/u\/2\/ac\/security\/lsa\" href=\"https:\/\/admin.google.com\/u\/2\/ac\/security\/lsa\">https:\/\/admin.google.com\/u\/2\/ac\/security\/lsa<\/a><\/p>\n<p>Unfortunately, you will <strong>also<\/strong> need to enable <strong>Less secure apps <\/strong>access for your accounts in Google Admin, otherwise you would continue to get the same error message:<\/p>\n<p>msmtp: authentication failed (method PLAIN)<br \/>\nmsmtp: server message: 535-5.7.8 Username and Password not accepted. Learn more at<br \/>\nmsmtp: server message: 535 5.7.8&nbsp; <a href=\"https:\/\/support.google.com\/mail\/?p=BadCredentials\">https:\/\/support.google.com\/mail\/?p=BadCredentials<\/a> **********.34 &#8211; gsmtp<br \/>\nmsmtp: could not send mail (account default from \/etc\/msmtprc)<\/p>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image-67.png\"><img loading=\"lazy\" decoding=\"async\" width=\"965\" height=\"276\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image_thumb-66.png\" border=\"0\"><\/a><\/p>\n<p>Change this to \u201cAllow users to manage their access to less secure apps\u201d and click on <strong>Save<\/strong>.<\/p>\n<h1>Send a test message<\/h1>\n<p>If everything works correctly, you can now send a test message:<\/p>\n<blockquote>\n<p>echo &#8216;test&#8217; | msmtp <a href=\"mailto:ceo@example.com\">ceo@example.com<\/a><\/p>\n<\/blockquote>\n<p>If this command returns without an error, then everything works.<\/p>\n<p>Also, if you refresh your App passwords view, you will see that the app password has been used (\u201clast used\u201d):<\/p>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image-68.png\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"336\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image_thumb-67.png\" border=\"0\"><\/a><\/p>\n<p>(this might not always be accurate as per my tests, though). <\/p>\n<p>If it would <strong>not <\/strong>work, you would get an output similar to the following:<\/p>\n<p><em>msmtp: authentication failed (method PLAIN)<br \/>\nmsmtp: server message: 535-5.7.8 Username and Password not accepted. Learn more at<br \/>\nmsmtp: server message: 535 5.7.8&nbsp; <\/em><a href=\"https:\/\/support.google.com\/mail\/?p=BadCredentials\"><em>https:\/\/support.google.com\/mail\/?p=BadCredentials<\/em><\/a><em> ***********.9 &#8211; gsmtp<br \/>\nmsmtp: could not send mail (account default from \/etc\/msmtprc)<\/em><\/p>\n<p>Note: This error will also appear if you delete your app password using the trash can icon you can see above. This, by the way is a useful feature of the App passwords: if you suspect a breach, you can simply delete the app password and set up your device with another app password.<\/p>\n<p>If you continue to get this error, check whether you have enabled less secure apps, as I have instructed you to do (above). \n<\/p>\n<p>Note II: you will get an info about freshly created app passwords in your email account:<\/p>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image-69.png\"><img loading=\"lazy\" decoding=\"async\" width=\"890\" height=\"74\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image_thumb-68.png\" border=\"0\"><\/a><\/p>\n<p>Note III: you will also get the sent messages in your sent folder:<\/p>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image-70.png\"><img loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"184\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2020\/10\/image_thumb-69.png\" border=\"0\"><\/a>\n<\/p>\n<h1>Ref<\/h1>\n<ul>\n<li><a title=\"https:\/\/doc.ubuntu-fr.org\/msmtp\" href=\"https:\/\/doc.ubuntu-fr.org\/msmtp\">https:\/\/doc.ubuntu-fr.org\/msmtp<\/a><\/li>\n<li><a title=\"https:\/\/stackoverflow.com\/questions\/63560494\/gmail-is-blocking-to-send-email-via-smtp\" href=\"https:\/\/stackoverflow.com\/questions\/63560494\/gmail-is-blocking-to-send-email-via-smtp\">https:\/\/stackoverflow.com\/questions\/63560494\/gmail-is-blocking-to-send-email-via-smtp<\/a><\/li>\n<li><a title=\"https:\/\/www.getmailbird.com\/setup\/access-gmail-com-via-imap-smtp\" href=\"https:\/\/www.getmailbird.com\/setup\/access-gmail-com-via-imap-smtp\">https:\/\/www.getmailbird.com\/setup\/access-gmail-com-via-imap-smtp<\/a><\/li>\n<li><a title=\"https:\/\/support.google.com\/a\/answer\/176600?hl=en\" href=\"https:\/\/support.google.com\/a\/answer\/176600?hl=en\">https:\/\/support.google.com\/a\/answer\/176600?hl=en<\/a> (this also mentions an SMTP relay service, which can be used as an alternative)<\/li>\n<\/ul>\n<h3>Bonus<\/h3>\n<p>Google mentions their <a href=\"https:\/\/support.google.com\/a\/answer\/176600?hl=en\">rate limits on this page<\/a>:<\/p>\n<ul>\n<li>10.000 recipients per day for the SMTP relay service (requires a static IP address or valid G Suite user sign-in)<\/li>\n<li>2.000 messages per day for the Gmail SMTP<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Wir sind dabei, auf Gmail umzusteigen, um die Verwaltung eines Mailservers delegieren zu k\u00f6nnen. Vorher haben wir ssmtp auf unserem Server verwendet, um E-Mails \u00fcber unseren eigenen Mailserver (Zimbra) zu versenden. Ich habe es jetzt geschafft, Gmail Workspace zum Laufen zu bringen, und w\u00fcrde gerne einige Hinweise dazu geben....<\/p>","protected":false},"author":830,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[452],"tags":[909,910,915,914,912,904,905,906,911,907,913,908],"class_list":["post-27765","post","type-post","status-publish","format-standard","hentry","category-tips-tricks","tag-admin","tag-administrator","tag-cron-daemon","tag-crontab","tag-getting-mail-to-work","tag-gmail","tag-gmail-suite","tag-gmail-workspace","tag-mail","tag-msmtp","tag-sending-mail","tag-ssmtp"],"_links":{"self":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/27765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/users\/830"}],"replies":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/comments?post=27765"}],"version-history":[{"count":1,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/27765\/revisions"}],"predecessor-version":[{"id":27766,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/27765\/revisions\/27766"}],"wp:attachment":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/media?parent=27765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/categories?post=27765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/tags?post=27765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}