{"id":240,"date":"2020-07-05T12:32:03","date_gmt":"2020-07-05T09:32:03","guid":{"rendered":"http:\/\/caupo.ee\/blog\/?p=240"},"modified":"2020-07-05T12:32:05","modified_gmt":"2020-07-05T09:32:05","slug":"how-to-install-msmtp-to-debian-10-for-sending-emails-with-gmail","status":"publish","type":"post","link":"https:\/\/caupo.ee\/blog\/2020\/07\/05\/how-to-install-msmtp-to-debian-10-for-sending-emails-with-gmail\/","title":{"rendered":"How to install msmtp to Debian 10 for sending emails with gmail"},"content":{"rendered":"\n<p>I am making this post because last 2 days I tried to install msmtp to my Debian 10 server. Previously I used ssmtp where I did not have any problems but it cannot be installed at the time of making this tutorial. Because nobody is maintaining the package anymore or something like this as far as I understood. <\/p>\n\n\n\n<p>I spend countless hours to the error that said my username and password is not accepted by Gmail. So here is my tutorial to how fully install it and configure it. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Installing required packages.<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install msmtp msmtp-mta<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Create an app password in Google for msmtp<\/h2>\n\n\n\n<p>This (Step 2.* in this tutorial) was the missing piece of the puzzle which weren&#8217;t in any of the msmtp tutorials I did through. I found out about it in one of the Postfix tutorials where it was included after many hours of trial and error. Because at first, I thought the msmtp config file where was password field had to be filled with the same password with what you log in as a person to your account. <\/p>\n\n\n\n<p>Go to: <a href=\"https:\/\/myaccount.google.com\">https:\/\/myaccount.google.com<\/a> and log into the email account you want to start sending the emails. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2.1: Select <strong>Security<\/strong> from the side menu and <strong>turn 2-Step Verification ON<\/strong>. <\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"654\" src=\"https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount-1024x654.png\" alt=\"\" class=\"wp-image-242\" srcset=\"https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount-1024x654.png 1024w, https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount-300x191.png 300w, https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount-768x490.png 768w, https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount.png 1150w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2.2: After that click on <strong>App passwords<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"663\" src=\"https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount1-1024x663.png\" alt=\"\" class=\"wp-image-243\" srcset=\"https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount1-1024x663.png 1024w, https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount1-300x194.png 300w, https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount1-768x497.png 768w, https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount1.png 1134w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2.3: Next up select <strong>Other (Custom name)<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"695\" height=\"639\" src=\"https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount2.png\" alt=\"\" class=\"wp-image-244\" srcset=\"https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount2.png 695w, https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount2-300x276.png 300w\" sizes=\"(max-width: 695px) 100vw, 695px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2.4: Fill in the name as msmtp for example<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"687\" height=\"514\" src=\"https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount3.png\" alt=\"\" class=\"wp-image-245\" srcset=\"https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount3.png 687w, https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount3-300x224.png 300w\" sizes=\"(max-width: 687px) 100vw, 687px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2.5: Get the password for your msmtp configuration file<\/h3>\n\n\n\n<p>Save this password to some notepad temporarily so you can copy &amp; paste it later to a configuration file because once you click <strong>DONE<\/strong> you cannot see the password again. At least I have not found a way to re-open this popup.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"737\" height=\"678\" src=\"https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount4.png\" alt=\"\" class=\"wp-image-246\" srcset=\"https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount4.png 737w, https:\/\/caupo.ee\/blog\/wp-content\/uploads\/2020\/07\/myaccount4-300x276.png 300w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Create a configuration file<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/msmtprc<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Configure msmtprc file<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>defaults\nauth           on\ntls            on\ntls_trust_file \/etc\/ssl\/certs\/ca-certificates.crt\nlogfile        ~\/.msmtp.log\naccount        gmail\nhost           smtp.gmail.com\nport           587\nfrom           username@gmail.com\nuser           username\npassword       password\naccount default : gmail<\/code><\/pre>\n\n\n\n<p>The <strong>username@gmail.com<\/strong> has to be changed in the config file with the email you used to create an app password in Google. <\/p>\n\n\n\n<p>The user field where is <strong>username<\/strong> has to be changed as well. For example, if your email is john.doe@gmail.com then change username to <strong>john.doe<\/strong>.<\/p>\n\n\n\n<p>The password field has to be changed also to the one the Google App password told you.<\/p>\n\n\n\n<p>So the configuration file would look like something like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>defaults\nauth           on\ntls            on\ntls_trust_file \/etc\/ssl\/certs\/ca-certificates.crt\nlogfile        ~\/.msmtp.log\naccount        gmail\nhost           smtp.gmail.com\nport           587\nfrom           john.doe@gmail.com\nuser           john.doe\npassword       fkelpwkdymcwslwo\naccount default : gmail<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Testing the email configuration<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"Message\" | mail -s \"Title\" youremailaddress@gmail.com<\/code><\/pre>\n\n\n\n<p>After that command, you should receive an email from your configured account.<\/p>\n\n\n\n<p>I hope this helps at least some of you. If you have any questions then feel free to ask and I will try to answer as fast as I can.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am making this post because last 2 days I tried to install msmtp to my Debian 10 server. Previously I used ssmtp where I did not have any problems but it cannot be installed at the time of making this tutorial. Because nobody is maintaining the package anymore or something like this as far &#8230; <a title=\"How to install msmtp to Debian 10 for sending emails with gmail\" class=\"read-more\" href=\"https:\/\/caupo.ee\/blog\/2020\/07\/05\/how-to-install-msmtp-to-debian-10-for-sending-emails-with-gmail\/\" aria-label=\"More on How to install msmtp to Debian 10 for sending emails with gmail\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/caupo.ee\/blog\/wp-json\/wp\/v2\/posts\/240"}],"collection":[{"href":"https:\/\/caupo.ee\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/caupo.ee\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/caupo.ee\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/caupo.ee\/blog\/wp-json\/wp\/v2\/comments?post=240"}],"version-history":[{"count":2,"href":"https:\/\/caupo.ee\/blog\/wp-json\/wp\/v2\/posts\/240\/revisions"}],"predecessor-version":[{"id":247,"href":"https:\/\/caupo.ee\/blog\/wp-json\/wp\/v2\/posts\/240\/revisions\/247"}],"wp:attachment":[{"href":"https:\/\/caupo.ee\/blog\/wp-json\/wp\/v2\/media?parent=240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/caupo.ee\/blog\/wp-json\/wp\/v2\/categories?post=240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/caupo.ee\/blog\/wp-json\/wp\/v2\/tags?post=240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}