我正在尝试向多个收件人发送电子邮件:
class SubscriberMailer < ApplicationMailer
default from: "email@gmail.com"
default to: Subscriber.all.map { |sub| sub.email }
def newsletter(subscriber)
@subscriber = subscriber
mail subject: "New newsletter"
end
end
在NewslettersController中:
def send(newsletter)
@subscribers = Subscriber.all
SubscriberMailer.newsletter(@subscribers).deliver
end
我收到错误:
ArgumentError in NewslettersController#index
An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.
感谢您的帮助!
答案 0 :(得分:1)
更改您的default to:
:
class SubscriberMailer < ApplicationMailer
default from: "email@gmail.com"
default to: Subscriber.pluck(:email).join(', ')
# some code here
end
答案 1 :(得分:0)
不是For Each c In Sheet14.Range("A2:A" & Sheet14.Range("A" & Rows.Count).End(xlUp).Row)
On Error Resume Next
'Populate level 1
Set cRoot = .AddRoot(sKey:=c.Value2, vCaption:=c.Value2)
Set cExtraNode = cRoot.AddChild("ML_" & c.Value2, "Meilensteine")
'Populate level 2
Set cNode = cRoot.AddChild(c.Offset(, 1).Value2, c.Offset(, 1).Value2)
'Populate level 3
If cNode.Level = 2 Then Set cNode = cNode.ParentNode
If Not IsEmpty(c.Offset(, 2).Value2) Then
Set cNode = cNode.AddChild(c.Offset(, 2).Value2, c.Offset(, 2).Value2)
End If
'Populate level 4
If Not IsEmpty(c.Offset(, 3).Value2) Then
If cNode.Level = 2 Then
Set cNode = cNode.AddChild(c.Offset(, 3).Value2, c.Offset(, 3).Value2)
Set cNode = cNode.ParentNode
ElseIf cNode.Level = 1 Then
Set cNode = cNode.Child.AddChild(c.Offset(, 2).Value2, c.Offset(, 2).Value2)
Set cNode = cNode.Child.AddChild(c.Offset(, 3).Value2, c.Offset(, 3).Value2)
Set cNode = cNode.ParentNode
End If
End If
Next
SMTP
中的某些内容无效。你使用真实的工作地址吗?如果没有,请尝试使用。
如果所有电子邮件都是真实的,那么您可以尝试类似
的内容Subscriber.all.map { |sub| sub.email }
希望它有所帮助!