私はsnedメールシステムを持っています.私はメールを送信するためにEventMachineを使用しています.しかし、私が送信したメールを受信したとき、私はhtmlコードを取得しましたが、htmlビュー.
EventMachine で conent_type = 'text/html' を設定するには?
THX
私はsnedメールシステムを持っています.私はメールを送信するためにEventMachineを使用しています.しかし、私が送信したメールを受信したとき、私はhtmlコードを取得しましたが、htmlビュー.
EventMachine で conent_type = 'text/html' を設定するには?
THX
%w(rubygems eventmachine mailfactory).each{|lib|require lib}
#gem install mailfactory -V
EM.run{
mail = MailFactory.new
mail.to = 'xxx@gmail.com'
mail.from = 'dongyuwei@weibo.com'
mail.subject = 'hi!'
#mail.text = 'hello world'
mail.html = '<h1>hello world</h1><a href="http://weibo.com">weibo.com</a>'
email = EM::P::SmtpClient.send(
:from=>mail.from,
:to=>mail.to,
:content=>"#{mail.to_s}\r\n.\r\n",
:header=> {"Subject" => mail.subject},
:domain=>"session.im",
:host=>'smtp.gmail.com',
:port=>587,
:starttls=>true,
:auth => {
:type=>:plain,
:username=>"xxxx@gmail.com",
:password=>"yyyyyyy"
},
:verbose => true
)
email.callback{
puts 'Email sent!'
}
email.errback{ |e|
puts 'Email failed!'
}
}
メールを作成するときは、テキストとHTMLの部分を含むマルチパートとして作成します。すべてのヘッダーなどを設定する必要があります。メールメッセージの例を次に示します。
Date: Wed, 13 Apr 2011 17:44:05 -0400
From: Me <me@example.com>
To: User Name <user@example.com>
Message-ID: <7672767637637@example.com>
Subject: test email
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="4da61925_46111ba5_b0f1"
Content-Transfer-Encoding: 8bit
--4da61925_46111ba5_b0f1
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Message here!
--4da61925_46111ba5_b0f1
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
<div>
html message here!
</div>
--4da61925_46111ba5_b0f1--