2011-03-08 52 views

回答

0

当你创建的电子邮件,打造为多部分文本和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-- 
1
%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!' 
     } 
    } 
+1

服务器失速当我运行此... – hfossli 2013-04-12 13:55:49