<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ssmtp &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/ssmtp/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Wed, 04 Dec 2019 02:27:24 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>ssmtp &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Ubuntu 使用 ssmtp 透過 Gmail 發送 email</title>
		<link>https://noter.tw/50/ubuntu-%e4%bd%bf%e7%94%a8-ssmtp-%e9%80%8f%e9%81%8e-gmail-%e7%99%bc%e9%80%81-email/</link>
					<comments>https://noter.tw/50/ubuntu-%e4%bd%bf%e7%94%a8-ssmtp-%e9%80%8f%e9%81%8e-gmail-%e7%99%bc%e9%80%81-email/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Mon, 17 Sep 2018 16:16:54 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ssmtp]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[2FA]]></category>
		<category><![CDATA[二段式驗證]]></category>
		<category><![CDATA[email]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=50</guid>

					<description><![CDATA[<p>小蛙的主機會設定登入通知，如果有人登入系統，會自動寄送登入通知，如果接收到 email 通知，但卻不是小蛙自己登入的，就可能是被攻擊了 (哭哭)，但是從不久前換了主機之後，這個功能失效了，但是另外一台&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/50/ubuntu-%e4%bd%bf%e7%94%a8-ssmtp-%e9%80%8f%e9%81%8e-gmail-%e7%99%bc%e9%80%81-email/" data-wpel-link="internal">Ubuntu 使用 ssmtp 透過 Gmail 發送 email</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>小蛙的主機會設定登入通知，如果有人登入系統，會自動寄送登入通知，如果接收到 email 通知，但卻不是小蛙自己登入的，就可能是被攻擊了 (哭哭)，但是從不久前換了主機之後，這個功能失效了，但是另外一台原本的主機卻一直都是正常運作的，這篇記錄處理的過程。 </p>



<span id="more-50"></span>



<p>小蛙透過 postfix 來寄送通知，但是從發現沒有收到 email 後，到 /var/log/mail.log 去看，出現了滿滿的錯誤訊息： </p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">550-5.7.1 This message does not have authentication information or fails to pass 550-5.7.1 authentication checks. To best protect our users from spam, the 550-5.7.1 message has been blocked. Please visit 550-5.7.1 https://support.google.com/mail/answer/81126#authentication for more 550 5.7.1 information.</pre>



<p>Google 了好一段時間，透過&nbsp;<a href="https://www.abuseat.org/lookup.cgi" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">CBL LOOKUP<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 可以查詢自己的 IP 有沒有被列入拒絕往來戶，小蛙看了半天，有些文章教人怎麼解除拒絕往來戶，有的教人怎麼加入 PTR 跟 Reverse DNS 來讓 Gmail 可以收到信，弄了一兩天，突然想到一個問題，嗯 ~ 既然小蛙的目的只是要寄信，主機的 IP 被 Google 拒絕，那 ~ 為什麼不直接用 Gmail 去寄信就好了。</p>



<h2 class="para wp-block-heading">安裝與設定 ssmtp</h2>



<p>Google 查了一些文章發現有一套寄信軟體叫做 ssmtp，可以直接設定使用 Gmail 寄信，使用的指令方式也很簡單，於是照著&nbsp;<a rel="noreferrer noopener nofollow external" href="https://www.mbeckler.org/blog/?p=398" target="_blank" data-wpel-link="external" class="wpel-icon-right">Sending email from Ubuntu server 16.04 via Gmail account<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 做，看英文不習慣的話，這邊有中文的「<a rel="noreferrer noopener nofollow external" href="https://blog.gtwang.org/linux/linux-send-mail-command-using-ssmtp-and-gmail/" target="_blank" data-wpel-link="external" class="wpel-icon-right">Linux 使用 SSMTP 與 GMail 以指令或程式自動寄信教學<span class="wpel-icon wpel-image wpel-icon-6"></span></a>」，很快就可以安裝好了，下面大概記錄一下步驟：</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">sudo apt-get update 
sudo apt-get install ssmtp 
sudo vim /etc/ssmtp/ssmtp.conf
# 
# Config file for sSMTP sendmail
# 
# The person who gets all mail for userids &lt; 1000 
# Make this empty to disable rewriting. 
root=xxxxxxx@gmail.com 
# 這邊填入寄送出 email 的人
# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com #mailhub=mail 
mailhub=smtp.gmail.com:587 
# 照著填
AuthUser=填入要用來寄信的 gmail 
AuthPass=填入 gmail 密碼 
UseTLS=YES 
UseSTARTTLS=YES 
# Where will the mail seem to come from? 
#rewriteDomain= 
rewriteDomain=gmail.com 
# 照著填 
# The full hostname 
#hostname=localhost 
hostname=填入你的主機名稱 
# Are users allowed to set their own From: address? 
# YES - Allow the user to specify their own From: address 
# NO - Use the system generated From: address 
FromLineOverride=YES 
# 照著填</pre>



<h2 class="para wp-block-heading">Gmail 二階段驗證(2FA)處理</h2>



<p>如果有開啟二階段驗證( 2FA )，請參考「<a href="https://blog.gtwang.org/linux/linux-send-mail-command-using-ssmtp-and-gmail/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Linux 使用 SSMTP 與 GMail 以指令或程式自動寄信教學<span class="wpel-icon wpel-image wpel-icon-6"></span></a>」。</p>



<h2 class="para wp-block-heading">測試發送信件</h2>



<p>最後測試看看</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">echo "Hello ~" | sudo ssmtp -vvv someone@example.org</pre>



<p>這邊如果出現錯誤的話，要把 hostname 改成 localhost 再試一次就可以囉！</p>



<h2 class="para wp-block-heading">設定郵件內容</h2>



<p>後來小蛙在 <a href="https://unix.stackexchange.com/questions/244294/how-to-add-subject-line-when-sending-email-output-of-find-using-ssmtp" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">How to add subject line when sending email output of find using ssmtp<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 找到比較適合自己編輯內容的好方法，下面補上小蛙自己的發 email 的指令($IP, $HOSTNAME, $NOW 是小蛙自己用的變數，根據自己需要的內容修改掉即可)，最後面用 printf 的原因是要換行，不然 echo 會把 \n 直接印出來。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">{ 
echo To: 收件者 email 
echo From: 寄件者 email 
echo Subject: 主旨 
printf "使用者資訊如下：\n\nIP：$IP\n登入到：$HOSTNAME\n登入時間：$NOW\n" 
} | ssmtp 收件者 email</pre>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/50/ubuntu-%e4%bd%bf%e7%94%a8-ssmtp-%e9%80%8f%e9%81%8e-gmail-%e7%99%bc%e9%80%81-email/" data-wpel-link="internal">Ubuntu 使用 ssmtp 透過 Gmail 發送 email</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/50/ubuntu-%e4%bd%bf%e7%94%a8-ssmtp-%e9%80%8f%e9%81%8e-gmail-%e7%99%bc%e9%80%81-email/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
