2012-05-23 152 views
0

在提交表單發送這裏的操作說明:http://www.padrinorb.com/guides/padrino-mailer你怎麼亞馬遜SES在Padrino

我已經加入對app.rb文件的傳遞方法:

class OscarAffiliate < Padrino::Application 
    register Padrino::Rendering 
    register Padrino::Mailer 
    register Padrino::Helpers 

    enable :sessions 

    set :delivery_method, :smtp => { 
    :address    => "email-smtp.us-east-1.amazonaws.com", 
    :port     => 587, 
    :user_name   => 'AKIAIQ5YXCWFKFXFFRZA', 
    :password    => 'AqMNMFecKSYR/TRu8kJgocysAL5SmIUsu2i8u/KAfeF/', 
    :authentication  => :plain, 
    :enable_starttls_auto => true 
    } 

但通過代通過Padrino和梅勒代,我沒有推薦的「會話」控制器,此應屬於:

post :create do 
    email(:from => "[email protected]", :to => "[email protected]", :subject => "Welcome!",  :body=>"Body") 
end 

我這麼想嗎?

我有一個辦公室的基本數據收集的形式,只需要一封電子郵件發送到5個收件人與郵件正文中的所有表單域。

感謝

+0

不是這個你真正的亞馬遜的鑰匙? – DAddYE

+0

我在帖子後重置他們。 –

回答

1

在我看來,你試圖以電子郵件形式提交後一個人(或多人)。可能您將信息從該表單保存到數據庫。我認爲你對如何使用Padrino郵件程序有點困惑。請允許我澄清一下:爲了發送電子郵件,使用Padrino的郵件程序功能以及全部內容,您必須創建一個Padrino Mailer(我已在下面概述了這一點)。然後,您必須配置該郵件程序,以便在調用它時將變量傳遞給它。然後可以在視圖中使用這些變量,在發送電子郵件之前,您的郵件程序會將其呈現到電子郵件正文中。這是完成你試圖做的事情的一種方式,它可能是最直截了當的。您可以在您的問題中提供的help page上的「Mailer Usage」下找到有關此過程的更多信息。我在下面概述了一個示例用法,適合於我相信您的需求。


說明

我扔在一起,此代碼示例和測試它反對我的AWS賬戶;它應該在生產中工作。

在你app/app.rb文件,包括以下內容(你已經這樣做了):

set :delivery_method, :smtp => { 
    :address    => 'email-smtp.us-east-1.amazonaws.com', 
    :port     => 587, 
    :user_name   => 'SMTP_KEY_HERE', 
    :password    => 'SMTP_SECRET_HERE', 
    :authentication  => :plain, 
    :enable_starttls_auto => true 
} 

然後在app/mailers/affiliate.rb創建梅勒:

# Defines the mailer 
DemoPadrinoMailer.mailer :affiliate do 
    # Action in the mailer that sends the email. The "do" part passes the data you included in the call from your controller to your mailer. 
    email :send_email do |name, email| 
    # The from address coinciding with the registered/authorized from address used on SES 
    from '[email protected]' 
    # Send the email to this person 
    to '[email protected]' 
    # Subject of the email 
    subject 'Affiliate email' 
    # This passes the data you passed to the mailer into the view 
    locals :name => name, :email => email 
    # This is the view to use to redner the email, found at app/views/mailers/affiliate/send_email.erb 
    render 'affiliate/send_email' 
    end 
end 

的加盟梅勒send_email觀點應設在app/view/mailers/affiliate/send_email.erb,看起來像這樣:

Name: <%= name %> 
Email: <%= email %> 

最後,您可以從您接受表單提交的任何方法(和控制器)內部調用您的郵件程序。請務必用實際的表單數據替換字符串。在這個例子中,我使用了一個貼create行動,這並沒有保存任何數據(因此用假數據的字符串):

post :create do 
    # Deliver the email, pass the data in after everything else; here I pass in strings instead of something that was being saved to the database 
    deliver(:affiliate , :send_email, "John Doe", "[email protected]") 
end 

我真誠地希望這可以幫助您在Padrino您的旅程,歡迎來到Stack Overflow社區!

真誠,

羅伯特Klubenspies