ruby 发送邮件

产品构建、打包、部署完需要发送邮件通知相关人员进行验证。请看过程

#encoding:utf-8
require 'mail'

#~ branch = ARGV.to_s.sub('[','').sub(']','')

# host = '10.0.2.44'
# port = '215'
# version = 'v2.1.6.1024'
# productPath = '\\10.0.2.44\public\shench\CrowdPackage\v2.1.5\20161209135558'

host = ARGV[0]
port = ARGV[1]
version = ARGV[2]
productPath = ARGV[3]

notesPath = '/home/CrowdProduct/releaseNotes.txt'

smtp = { :address => 'smtp.exmail.qq.com',
                 :port => '25',
                 :domain => 'xxxxxxxx.com',
                 :user_name => 'xxxx@xxxxnets.com',
                 :password => 'xxxxxxx',
                 :enable_starttls_auto => true,
                 :openssl_verify_mode => 'none' }
Mail.defaults { delivery_method :smtp, smtp }
puts "start send mail"
mail = Mail.new do
  from 'xxxxhui@xxxxets.com'
  to 'xxxx,xxxx'
  subject "【crowdProduct】【#{version}】Product build complete, please test."
  body "
 product path: #{productPath}
 web site: http:\//#{host}:#{port}\n
 【release notes】
  #{File.readlines(notesPath).join}"
 end
mail.deliver!
puts "mail done"

 

发送的邮件内容从该文件获取:notesPath = '/home/CrowdProduct/releaseNotes.txt'

下一节将教你如何获取git commit 信息,规整后作为release notes

 

收到的邮件效果如下: 测试人员收到邮件后,直接登录web页面即可测试

 

posted @ 2017-03-30 09:54  Fithon  阅读(1118)  评论(1编辑  收藏  举报