视图有链接时无法发送电子邮件

时间:2012-11-02 16:01:45

标签: ruby-on-rails ruby-on-rails-3.2 actionmailer

我使用的是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 abhimanyu@gmail.com (6117ms)
 Date: Fri, 02 Nov 2012 20:59:33 +0530
 From: invitation@dev.tld
 To: abhimanyu@gmail.com
 Message-ID: <5093e6dd6a275_14f733fc536034cd444087@Abhimanyus-iMac.local.mail>
 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

任何帮助找出问题都将不胜感激。

提前致谢。

1 个答案:

答案 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