0
我有一個smail郵件系統。我使用EventMachine發送郵件。但是當我收到我發送的郵件時,我剛剛得到了html代碼,但HTML視圖。如何通過EventMachine發送帶有content_type ='text/html'的郵件
如何在EventMachine中設置conent_type ='text/html'?
THX
我有一個smail郵件系統。我使用EventMachine發送郵件。但是當我收到我發送的郵件時,我剛剛得到了html代碼,但HTML視圖。如何通過EventMachine發送帶有content_type ='text/html'的郵件
如何在EventMachine中設置conent_type ='text/html'?
THX
當你創建的電子郵件,打造爲多部分文本和HTML部分。你需要設置所有的頭,等下面是一個例子郵件:
Date: Wed, 13 Apr 2011 17:44:05 -0400
From: Me <[email protected]>
To: User Name <[email protected]>
Message-ID: <[email protected]>
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--
%w(rubygems eventmachine mailfactory).each{|lib|require lib}
#gem install mailfactory -V
EM.run{
mail = MailFactory.new
mail.to = '[email protected]'
mail.from = '[email protected]'
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=>"[email protected]",
:password=>"yyyyyyy"
},
:verbose => true
)
email.callback{
puts 'Email sent!'
}
email.errback{ |e|
puts 'Email failed!'
}
}
服務器失速當我運行此... – hfossli 2013-04-12 13:55:49