2012-11-02 68 views
1

我正在使用ruby 1.9.3p194和Rails 3.2.3。當視圖有鏈接時無法發送電子郵件

我在發送模板中有鏈接的電子郵件時遇到問題。我已經寫了下面的代碼:

invitation_mailer.rb

def event_invitation(user, event) 
    @user = user 
    @event = event 
    mail(:to => @user.email, :subject => "Invitation to participate in #{@event.name} event") 
end 

event_invitation.html.haml

Hello, 

%br 
%br 

Your friend #{@event.user.full_name} has invited you to participate in #{@event.name} event. If you want to accept 
this invitation, use the following link: 

= link_to calendar_index_url, calendar_index_url 

%br 
%br 

#{t('shared.team')} 

user.rb

def xyz 
    ... 
    InvitationMailer.event_invitation(self, event).deliver 
end 

如果我刪除鏈接線的查看,我能夠接收電子郵件,但不能與視圖內的鏈接。但日誌顯示電子郵件已發送。

LOG

Sent mail to [email protected] (6117ms) 
Date: Fri, 02 Nov 2012 20:59:33 +0530 
From: [email protected] 
To: [email protected] 
Message-ID: <[email protected]> 
Subject: Invitation to participate in new event event 
Mime-Version: 1.0 
Content-Type: text/html; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

Hello, 
<br> 
<br> 
Your friend Abhimanyu Kumar has invited you to participate in new event event. If you want to accept 
this invitation, use the following link: 
<a href="http://localhost:3000/calendar">http://localhost:3000/calendar</a> 
<br> 
<br> 
Dev Team 

任何幫助找出問題,將不勝感激。

在此先感謝。

+0

檢查您的垃圾郵件文件夾?發送到其他電子郵件地址? –

回答

2

您是否在您的環境配置文件中指定了ActionMailer default_url_options?無論是在config/environments/development.rbconfig/environments/production.rb(取決於你的工作環境),請確保您包括以下內容:

config.action_mailer.default_url_options = { :host => "example.com" } 

在這裏看到更多的信息:http://api.rubyonrails.org/classes/ActionMailer/Base.html#label-Generating+URLs