2012-11-02 38 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