1

我正在使用 ruby​​ 1.9.3p194 和 Rails 3.2.3。

我在发送模板中包含链接的电子邮件时遇到问题。我写了以下代码:

邀请邮件程序.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')}

用户.rb

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

如果我删除视图中的链接行,我可以接收电子邮件,但不能使用视图内的链接。但是日志显示已经发送了一封电子邮件。

日志

 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

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

提前致谢。

4

1 回答 1

2

default_url_options您是否在环境配置文件中指定了 ActionMailer ?无论是在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

于 2012-11-02T17:11:09.697 回答