1

アプリケーションからメールを送信するために消印を使用しています。通常の電子メールでは正常に機能しますが、電子メールの添付ファイルは機能しません。

ローカルでは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です。開発モードでは、添付ファイル付きのメールを受け取ります。ただし、ステージングおよび開発モードではありません。

ヘルプや提案をいただければ幸いです。ありがとう。

4

2 に答える 2

1

最後に、上記の問題の実際の原因を見つけることができます。

私は gem のpostmark-railsを使用しています。以前は消印は電子メールの添付ファイルをサポートしていませんでした。そのため、最近、添付ファイルをサポートするように gem が拡張されました。残念ながら、古いバージョンを使用していたため、gem のバージョンを最新のものに更新する必要があります。問題の 1 つで言及されています: attachment-issue

また、S3に保存されたファイルのURLを送信しようとしていたので、その代わりにURLからそのファイルを読み取って添付ファイルとして送信する必要があります

  require "open-uri"

  def send_refer_pt_request(params, attachment)

    if attachment.present?
      mime_type = MIME::Types.type_for(attachment).first
      url_data = open(attachment).read()
      attachments["#{attachment.split('/').last}"] = { mime_type: mime_type,
        content: url_data }
    end

    mail(
      to:      <some_email>,
      subject: "Refer Request",
      tag:     "refer_request")
  end
于 2013-12-12T12:43:04.157 に答える