[英]In ruby on rails, how do you decode a content-transfer-encoding base64 Mail object
[英]How to change the mailer Content-Transfer-Encoding settings in Rails?
“內容傳輸編碼”設置默認設置為“7 位”。 郵件服務器 Postfix 將電子郵件標頭分解為 1000 個字符,這意味着如果您有一封很長的電子郵件(例如使用 HTML),您最終會在文本或鏈接中間有空格。 (有關更多信息,請參閱此線程:http://tech.groups.yahoo.com/group/postfix-users/message/273296 )
按照 Rails ActionMailer 文檔 (http://api.rubyonrails.org/classes/ActionMailer/Base.html),將以下代碼添加到我的應用程序文件應該可以,但它不起作用:
ActionMailer::Base.default 'Content-Transfer-Encoding' => 'quoted-printable'
我仍然使用默認值:
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_50166adf1e043_1b9810829142282d";
charset=UTF-8
Content-Transfer-Encoding: 7bit
我的電子郵件看起來像這樣:
def new_registered_user(user_id)
@user = User.find(user_id)
set_locale @user.locale
mail(
:subject => i18n_subject,
:to => @user.email_with_name
) do |format|
format.text { render :layout => 'text_email' }
format.html
end
end
關於我還應該改變什么的任何想法?
我發現在 Mail 對象上設置(未記錄的)transport_encoding 有效:
m = mail(...)
m.transport_encoding = "quoted-printable"
m.deliver
我無法獲得通過 ActionMailer 設置 Content-Transfer-Encoding 的記錄方法。
我的環境:rails (3.1), mail (~> 2.3.3)
如果您使用自定義郵件程序類,則可以將其設置為郵件程序類中的默認選項,如ActionMailer::Base 文檔中所述
class Notifier < ApplicationMailer
default 'Content-Transfer-Encoding' => '7bit'
end
我最近也遇到了這個問題。 Rails 默認為quoted-printable
,但這導致我在網絡郵件客戶端中出現渲染問題。 新行呈現為=0D
,網絡郵件客戶端呈現不正確。
我對此的解決方案是僅更改 html 部分的內容編碼,因為我還發送了一個單獨的文本部分並且不想更改其編碼。 html
方法采用content_transfer_encoding
參數,避免需要臨時變量:
mail do |format|
format.text { ... }
format.html(content_transfer_encoding: '7bit') { ... }
end
文檔引用使用default 'Content-Transfer-Encoding'...
但這僅在不直接調用mail
方法時有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.