1
我正嘗試在本地開發環境中使用ActionMailer發送電子郵件。一切工作都很好,除了附件。Rails 5 Action Mailer jpg沒有正確傳輸
在以下代碼塊中,我將JPG文件附加到電子郵件「Testbild.jpg」,其大小爲6,19KB。但是,接收者會看到一封電子郵件,其中只有一個同名文件,其大小僅爲96字節。
def welcome_email(user)
@user = user
@url = 'http://example.com/login'
attachments['Testbild.jpg'] = File.read("#{Rails.root}/public/images/Testbild.jpg")
mail(to: @user.kontakt.email, subject: 'Welcome to My Awesome Site')
end
這是我的ActionMailer配置在development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { host: 'localhost', port: 3001 }
config.action_mailer.smtp_settings = {
user_name: "[email protected]",
password: "************",
domain: "xclirion.de",
authentication: :plain,
address: "smtp.xclirion.de",
openssl_verify_mode: OpenSSL::SSL::VERIFY_NONE,
enable_starttls_auto: true,
port: 587
}
我發現,96個字節接收到的文件是完全一樣的前96個字節我的源文件。其餘的似乎已經失去。
這裏出了什麼問題?我如何強制RoR發送整個文件?
嘗試此'attachments.inline [ 'Testbild.jpg'] = File.read(「#Rails.root} /公共/圖像/ Testbild .jpg「)' – hgsongra