【发布时间】:2015-05-22 12:24:33
【问题描述】:
我需要一个脚本,它可以自动从我的公司网络邮件电子邮件 ID 发送特定数据。
到目前为止,我能够从 gmail id 发送自动电子邮件。但我无法为我的 webmail id 配置它。
如果需要任何配置更改或我需要为此设置服务器,请告诉我。(如果可能,还请帮助我如何配置服务器)
这是我正在使用的 Ruby 函数
def send_mail(to_recepient,data,mailSubject,extraBodyText,sender_info)
options = { :address => "smtp.gmail.com",
:port => 587,
:domain => 'mail.gmail.com',
:user_name => sender_info[:senderName],
:password => sender_info[:senderPassword],
:authentication => 'plain',
:enable_starttls_auto => true }
Mail.defaults do
delivery_method :smtp, options
end
Mail.deliver do
to "#{to_recepient}"
from 'mailtest20152@gmail.com'
subject mailSubject
body stringData
fh=File.open('attachment_file',"w")
fh.puts data
add_file :filename => 'attachment_file', :content => data
end
File.unlink('attachment_file')
end
【问题讨论】:
-
我认为这不是编码问题。如果这适用于 gmail,它也应该适用于任何其他为您提供 smtp 服务器的网络邮件。只需在您的网络邮件中查看它的配置。
标签: ruby smtp sendmail webmail