通过企业网络邮件自动化电子邮件发送过程

时间:2015-05-22 12:24:34

标签: ruby smtp sendmail webmail

我需要一个自动从公司网络邮箱电子邮件ID发送特定数据的脚本。

直到现在我能够通过gmail ID发送自动电子邮件。但我无法为我的网络邮件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

1 个答案:

答案 0 :(得分:1)

我遇到了类似的问题。您可以为特定的smtp服务器配置邮件程序,如下所示:

options = { :address              => "smtp.yourdomain.com", #address can differ
          :port                 => 25  }

别忘了添加:

config.action_mailer.delivery_method = :smtp

不需要提供密码和用户名,但请记住在电子邮件中指定from字段(正如您已经做过的那样)。