我正在使用邮戳从应用程序发送电子邮件。它适用于普通电子邮件,但电子邮件附件不起作用。
它在本地工作正常,因为在本地我有 smtp+邮戳设置(要在本地工作,我们需要有邮戳和 smtp)
但是在登台和生产上,我只使用 SMTP 设置
config/environments/staging.rb和config/environments/production.rb
POSTMARK_API_KEY = "<my-api-key>"
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_key => POSTMARK_API_KEY }
配置/环境/development.rb
POSTMARK_API_KEY = "<my-api-key>"
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.postmarkapp.com",
:port => 25,
:domain => 'example.com',
:user_name => POSTMARK_API_KEY,
:password => POSTMARK_API_KEY,
:authentication => 'plain',
:enable_starttls_auto => true }
user_mailer.rb
class UserMailer < ActionMailer::Base
default from: DEFAULT_EMAIL
def send_request(params, attachment)
if attachment.present?
mime_type = MIME::Types.type_for(attachment).first
attachments["#{attachment.split('/').last}"] = { mime_type: mime_type,
content: attachment, encoding: 'base64' }
end
mail(
to: <some_email>,
subject: "Refer Request",
tag: "refer_request")
end
这attachment
是保存在 S3 上的文件的 url。在开发模式下,我收到带有附件的电子邮件。但不在分期和开发模式下。
任何帮助或建议将不胜感激。谢谢。