2016-08-03 65 views
0

我想弄清楚如何使用Rails 4,以便我的設計電子郵件可以使用Sendgrid模板發送。Rails 4,使用sendgrid模板設計郵件

我在Sendgrid中創建我的第一個模板。

我看不到如何給鏈接一個名字。 sendgrid模板頁面上的插入鏈接按鈕允許您選擇鏈接是URL還是電子郵件。我選擇了URL。然後它有一個選項來完成https:地址。我想給這個地址一個蒙面的名字(即'Schedule' - 他的鏈接到https日程安排網址)。

如何在Sendgrid模板中執行此操作?

另外,我有一個鏈接到設計確認令牌:

<%= link_to 'Confirm account', confirmation_url(@resource, confirmation_token: @token) %> 

如何給該令牌在sendgrid電子郵件模板Sendgrid?

回答

1

你必須發佈更多的錯誤信息才能得到答案。但這可能會有所幫助。

你梅勒

class UserMailer < ApplicationMailer 
default from: '[email protected]' 

def welcome_email(user) 
    @user = user // User 
    @url = 'Url' 
    mail(to: @user.email, subject: 'Confirm your account') 
end 
end 

在你的config /環境/ development.rb或production.rb

config.action_mailer.delivery_method = :smtp 
config.action_mailer.default_url_options = { :host => 'localhost:3000' } 
config.action_mailer.smtp_settings = { 
address:    'smtp.gmail.com', 
port:     587, 
domain:    'example.com', 
user_name:   '', 
password:    '', 
authentication:  'plain', 
enable_starttls_auto: true 
} 

在你的控制器 UserMailer.welcome_email(@user).deliver_now或deliver_later

在你的視圖文件

http://myserver.com/accounts/confirm?confirmation_token=<%[email protected]_token%>

這對我的作品,希望你也一樣。

+0

@pradeep_sapkota - 謝謝你的提示。這不是我想要做的。 Sendgrid有一個誘人的系統,允許您創建模板以用於發送交易電子郵件。在那個模板生成器中,我試圖放置一些鏈接。一個問題是與一個第三方url建立一個普通的鏈接 - 顯示爲一個單詞而不是url路徑。第二個問題是給該模板一個鏈接,這是一個設計確認令牌。 – Mel

+0

這必須解決您的問題https://sendgrid.com/docs/API_Reference/SMTP_API/substitution_tags.html –

+0

你知道,這有助於解釋如何使用這些標籤在Rails應用程序中調用sendgrid取得了模板的任何資源。這些文件涉及基於使用哪種語言需要不同類型的替代標籤。有沒有任何指南可以幫助解釋這個rails應用程序? – Mel