0
所以我設法創造了一些有趣的行爲,我不知道如何調試。我有一個由模型和表格支持的郵件程序。當用戶創建消息時,方法會生成一組聯繫人來發送電子郵件。由於已經在控制檯中進行了測試,因此我們會繼續。如何使郵件不會重複自己
模型只是通過收件人的數組itterates ...
class ContactMessage < ActiveRecord::Base
...
def send_message(user)
self.recipients.each do |rec|
unless rec.include?("@")
contact = Contact.find(rec)
to = "\"#{contact.first_name} #{contact.last_name}\" <#{contact.email}>"
else
to = rec
contact = user.contact.new('email' => rec)
end
ContactMail.direct_mail(user, self, to, contact).deliver
end
end
end
應該然後做出新的呼叫到ContactMail.direct_mail方法N多。
class ContactMail < ActionMailer::Base
helper :mail
def direct_mail(user, contact_message, to, contact)
@user = user
@contact = contact
@contact_message = contact_message
@theme = @contact_message.theme
mail(:to => to, :subject => contact_message.subject, :from => "no-reply" << @user.website.domain, :reply_to => @user.email)
end
...
end
mail()方法使用提供的@instance變量呈現視圖。
<%= @user.website.title %>
<%= @user.website.motto %>
============================================================
<%= @contact_message.message.html_safe.gsub(/<\/?[^><]*>/i, "") %>
============================================================
This message is from <%= @user.first_name << " " << @user.last_name << " of " << @user.business%>
Please reply to <%= @user.email %>
<%= @user.telephone %>
<%= @user.address_l1%>
<%= @user.address_l2 unless @user.address_l2.blank?%>
<%= @user.city << ", " << @user.state << " " << @user.zip %>
<%= @user.website.domain %>
一切都很好,我使用MailCatcher接收所有的電子郵件和終端說,他們發送。
但是,在第一個發送後的每個郵件都會一直堆放在彼此之間!它produceses像
Healthy Living
Where massage makes health.
============================================================
asdfasdfasdfasd
============================================================
This message is from Adam Fluke of Healthy Living LLC Fluke of Healthy Living LLC Fluke of Healthy Living LLC Fluke of Healthy Living LLC Fluke of Healthy Living LLC Fluke of Healthy Living LLC Fluke of Healthy Living LLC Fluke of Healthy Living LLC Fluke of Healthy Living LLC Fluke of Healthy Living LLC
Please reply to [email protected]
504-638-2222
1822 Moss St
Apt E
New Orleans, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119, AL 70119
healthyliving.org
(這將是第五消息發送,它發送的每一封電子郵件逐步惡化得到。)
這是我不明白的,根據我的郵件和理解方法調用,每個發送的消息應該是他們自己獨特的對象,不應該與其他人互動。然而,顯然是。這發生在+ =和< <,在文本和HTML。 WTF?
任何想法或幫助讚賞。
事情變得醜陋,所以我刪除了git分支並重新開始。作爲重寫的一部分,我用+代替。 – AdamCooper86 2012-07-30 15:17:52