アプリケーションからメールを送信するために消印を使用しています。通常の電子メールでは正常に機能しますが、電子メールの添付ファイルは機能しません。
ローカルではsmtp + postmark設定があるため、ローカルで正常に動作します(ローカルで動作させるには、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 }
config/environments/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
S3attachment
に保存したファイルのURLです。開発モードでは、添付ファイル付きのメールを受け取ります。ただし、ステージングおよび開発モードではありません。
ヘルプや提案をいただければ幸いです。ありがとう。