2012-02-28 33 views
0

我正在使用Ruby通過Google應用發送電子郵件。電子郵件正在發送和接收。問題在於該電子郵件顯示在我的Gmail收件箱中,因爲它被髮送給未公開的收件人,並且沒有任何主題。Ruby電子郵件發送未公開收件人

require 'rubygems' 
require "tlsmail" 

message = <<MESSAGE_END 
From: From Address <[email protected]> 
To: My Address <[email protected]> 
Subject: The Subject 
Date: #{Time.now.rfc2822} 

This is the email body. 

MESSAGE_END 

Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) 
Net::SMTP.start('smtp.gmail.com', 587, 'smtp.gmail.com', '[email protected]', 'password', :login) do |smtp| 
smtp.send_message(message, '[email protected]', '[email protected]') 
end 

正如我所說,收到的電子郵件。標題如下:

from:From地址To:我的地址標題:標題日期:2012年2月28日星期二09:54:22 -0500 [email protected] sender-time:發送時間爲9 :54 AM(GMT-08:00)。當前時間:上午7:45。 ✆至: 日期:2012年2月28日星期二上午9:54

由於缺少主題。

這並不是什麼大問題,但我想盡可能使它像一個典型的電子郵件進來。

回答

0

我不知道您是否堅決使用tlsmail,但我已經在Pony和Google Apps上取得了成功。下面是我的一個變形例:

require 'pony' 

email_data = { 
    :from    => 'Mailer <[email protected]>', 
    :to    => '[email protected]', 
    :subject   => 'Some subject', 
    :body    => 'A plain text body', 
    :html_body  => haml :email, # render html email using haml 
    :port    => '587', 
    :via    => :smtp, 
    :via_options  => { 
    :address     => 'smtp.gmail.com', 
    :port      => '587', 
    :enable_starttls_auto  => true, 
    :user_name    => '[email protected]', 
    :password     => 'mailer_password', 
    :authentication   => :plain, 
    :domain     => 'mydomain.com' 
    } 
} 
Pony.mail(email_data) 

我的助手(我使用西納特拉)這個包裹起來,並通過在特定的參數,合併那些使用默認選項(如圖所示)。如果您也想看,我會更新。

+0

非常感謝,效果很好。 – Peter 2012-02-29 22:57:28

+0

@Peter爲了讓您知道,如果您要製作某種您想要回復的用戶生成電子郵件(例如聯繫表單,您收到回覆用戶),則需要使用這些電子郵件與您將回應的電子郵件不同。這是Google Apps的侷限性,但試圖弄清楚它可能令人沮喪。 – 2012-03-01 06:06:21

相關問題