使用 Ruby on Rails 和 OAuth2 发送电子邮件 (Office 365)

Sending Email with Ruby on Rails and OAuth2 (Office 365)

提问人:Leon 提问时间:1/12/2023 更新时间:1/12/2023 访问量:537

问:

我们的应用程序建立在

  • 红宝石 2.2.1p85
  • 轨道 4.2.5

我们使用 ActionMailer 发送通知电子邮件。我依赖 ActionMailer 和 SMTP 的旧代码是:

  ActionMailer::Base.smtp_settings = {
    :address => "smtp.office365.com",
    :port => 587,
    :domain => "smtp.office365.com",
    :authentication => :login,
    :user_name => "MY_EMAIL_ADDRESS",
    :password => "MY_PASSWORD",
    :enable_starttls_auto => true
  }

  ......

  def general_mail (to, subject, content, attachmts = [] )
    attachmts.each do |attachment|
        attachments[File.basename(attachment)] = File.read(attachment, mode: 'rb')
    end
    
    mail(to: to, subject: subject) do |format|
        format.text { render :text => content }
    end
  end

代码现在不起作用,因为旧的身份验证方法将被弃用并切换到 OAuth2。

有人可以帮我使通知电子邮件代码在 Oauth2 下再次工作吗?

非常感谢!

Ruby-on-Rails Ruby 电子邮件 Office365

评论

0赞 Leon 1/12/2023
我在网上搜索了一下,没有找到太多关于邮件程序如何与 Oauth2 配合使用的文档
1赞 manuwell 1/12/2023
我发现这个问题可能会有所帮助
1赞 manuwell 1/12/2023
除了前面的评论外,这里还介绍了如何在 Rails 上实现设置。据我所知,您将不得不从 smtp 切换到 imap,才能在您的设置中使用authentication: "XOAUTH2"

答: 暂无答案