Setup JIRA standalone 3.13.3 with Gmail SMTP

Gmail use the port 465/587 and STARTTLS for its SMTP. This gets many application have trouble using Gmail SMTP to send mail. That is from what I observe.
Recently I recommand JIRA to my boss and he agree to give it a go. I am sure good and commercial product like JIRA must be able to
support Gmail SMTP. But that is still not a easy setting as normal SMTP.
Gmail使用連接埠465/587加上STARTTLS作為它的SMTP通訊.這讓很多網頁應用程式要用Gmail的SMTP發送郵件時遇上困難.至少我遇到不少這樣的例子.
最近我建議我上司使用JIRA而他同意試用看看.我很肯定像JIRA這種良好的商業產品一定可以跟Gmail的SMTP溝通.只是跟一般SMTP的設定比較還是不太簡單.

I first try to setup by reading their document about SSL SMTP, which is this one. WARNING, This procedure won’t work.
And then of course I turn to their support since I brought their product. Their live chat service is quite good. Here is how I successfully connect my JIRA with Gmail. I am writing this down because if you want to make it work, you will need information from different parts of different document. And those document are not easy to understand if you have little experience on TOMCAT and JAVA. I am going to write this in a way that average technical person could understand.

我首先邊讀他們關於SSL SMTP的使用文件邊設定.就是這篇.警告,這篇的方法不可行.
然後因為我買他們的產品,我當然是去找他們的支援.他們的即時對話服務還不錯.下面就是我成功連接我的JIRA和Gmail的方法.我把他寫下來因為如果你也想像我那樣設定,你需要很多來自不同文件的資訊.而這些文件如果你沒有使用過TOMCAT和JAVA就會不是那麼容易看得懂.我會用一般技術人員都看得懂的方式去寫下來.

You will need to have SSL support, I use OPENSSL, an open source SSL and TLS protocol implementation. REMARK, this may not be necessary since I later found out that we are connection Gmail SMTP with JNDI but not SSL. After you install OpenSSL, use command line (console), go to %OPENSSL%\bin. run this command to get Gmail smtp public key.
你需要能支援SSL,我用的是OPENSSL,一個開源的SSL和TLS協定實作.注意,這可能並不是必需的,因為我後來發現我們並不是用SSL而是用JNDI去跟Gmail的SMTP溝通.在你安裝OpenSSL後,運行命令提示字元(M$的翻譯還真爛…),然後到%OPENSSL%\bin.運行這個命令去取得Gmail smtp的公用金鑰.

cmd>openssl s_client -connect smtp.gmail.com:465 > c:\key.txt

Then open the text file and copy the public key. Like the following
然後打開那個文字檔並複制那個公用金鑰.像下面的

-----BEGIN CERTIFICATE-----
MIICiTCCAfKgAwIBAgIBADANBgkqhkiG9w0BAQQFADB/MQswCQYDVQQGEwJBVTEM
MAoGA1UECBMDTlNXMQ8wDQYDVQQHEwZTeWRuZXkxEjAQBgNVBAoTCUF0bGFzc2lh
bjEaMBgGA1UEAxMRY3ZzLmF0bGFzc2lhbi5jb20xITAfBgkqhkiG9w0BCQEWEmlu
Zm9AYXRsYXNzaWFuLmNvbTAeFw0wNTA5MjMwNjUyNTNaFw0wNjA5MjMwNjUyNTNa
MH8xCzAJBgNVBAYTAkFVMQwwCgYDVQQIEwNOU1cxDzANBgNVBAcTBlN5ZG5leTES
MBAGA1UEChMJQXRsYXNzaWFuMRowGAYDVQQDExFjdnMuYXRsYXNzaWFuLmNvbTEh
MB8GCSqGSIb3DQEJARYSaW5mb0BhdGxhc3NpYW4uY29tMIGfMA0GCSqGSIb3DQEB
AQUAA4GNADCBiQKBgQDhwAgx/gDgKe9tBjUCj7JtVkwQSzj2Dq0PHiJu1AWUYWFW
ivbBWaWSYbt/w9vIRSL8OlGVOLnlFOH5o7QIpIBZvd3xBMv6DxMijM86/hu8QTPt
KcMuqBTGpu1T846SzNncj883wSE1hXxezCgEFCsqyC7dVX4l0Ay6zgzkt2wc3QID
AQABoxUwEzARBglghkgBhvhCAQEEBAMCBkAwDQYJKoZIhvcNAQEEBQADgYEAJOgg
O4brCcQa3IgONo8UmLcHo6Rq+Py6ZA3ueUegy/uyQ358JUeL4kktXuYL9gAPCuMc
hsC1iyaOrWY/S9S67w2ZWqc+uYX9ophFHkxK1r3YiaiMpEzMyB12VWSrOITcR0LV
7NTWfxfPLUpkDbj+Mw/66QJkI0lqBvcKn3KXI74=
-----END CERTIFICATE-----

Create a text file C:\certs\imapd.pem, paste the key into it.
建立一個文字檔C:\certs\imapd.pem,把金鑰貼在裡面.
We now add the key into Java keystore by running the following command at %JAVA_HOME%\
接下來把金鑰加到Java的keystore裡.在%JAVA_HOME%\裡執行下面的命令

bin\keytool -import -file c:\certs\imapd.pem -alias smtp.gmail.com -keystore lib\security\cacerts

Do not go inside bin folder. This command will add the key to java default keystore.
Then we setup our TOMCAT like this. Modify %JIRA%\conf\server.xml
不要進到bin資料夾. 這命令會把金鑰加到java預設的keystore裡.
然後我們設定我們的TOMCAT如下.修改%JIRA%\conf\server.xml

<Context path="" docBase="${catalina.home}/atlassian-jira" reloadable="false">
 ....
<Resource name="mail/GmailSmtpServer"
 auth="Container"
 type="javax.mail.Session"
 mail.smtp.host="smtp.gmail.com"
 mail.smtp.port="465"
 mail.smtp.auth="true"
 mail.smtp.user="myusername@gmail.com"
 password="mypassword"
 mail.smtp.starttls.enable="true"
 mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
 />
 </Context>

If you don’t have this resource block, just add a new one. Replace user and password with your own account.
Next, Cut %JIRA%\atlassian-jira\WEB-INF\lib\javamail-1.3.2.jar and %JIRA%\atlassian-jira\WEB-INF\lib\activation-1.0.2.jar And paste the files into %JIRA%\common\lib.
如果你沒有這資源,就加一個新的.把使用者和密碼改成你自己的帳號.
下一步, 剪下%JIRA%\atlassian-jira\WEB-INF\lib\javamail-1.3.2.jar和%JIRA%\atlassian-jira\WEB-INF\lib\activation-1.0.2.jar 並貼上到%JIRA%\common\lib.

And then restart JIRA and perform the last step.
重新啟動你的JIRA並進行最後一步
Set up your mail server in JIRA: Administrator > Global Settings > Mail Servers
設定你的JIRA郵件服務器: 管理者介面->全域設定->郵件伺服器
Name your file: Name it whatever you would like.(隨意)
Set your from address: Name it whatever you would like.(隨意)
Set your email prefix: Name it whatever you would like.(隨意)
Leave server name, user name and password blank.
把伺服器名,使用者名稱和密碼留空白
SMTP Port: 25
JNDI Location: java:comp/env/mail/GmailSmtpServer
(Replace GmailSmtpServer with whatever you set your Resource name=”mail/GmailSmtpServer”)
(GmailSmtpServer代入任何之先前設定的資料名稱 name=”mail/GmailSmtpServer”)
You are now ready to use Gmail SMTP.
你已經準備好用Gmail SMTP.
reference: HERE.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s