开发者

Ruby Large HTML emails getting error, limit to header size

def mailTo(subject,msg,folks)
begin
Net::SMTP.start('localhost', 25) do |smtp|
  smtp.send_message "MIME-Version: 1.0\nContent-type: text/html\nSubject: #{subject}\n#{msg}\n#{DateTime.now}\n", 'person@domain.com', folks
end


rescue => e
    puts "Emailing Sending Error开发者_如何学Go - #{e}"
  end
end

when the HTML is VERY large I get this exception

Emailing Sending Error - 552 5.6.0 Headers too large (32768 max)

how can i get a larger html above max to work with Net::SMTP in Ruby


This might not be a restriction imposed by the library, but rather a restriction imposed by the service you are using to send. It kinda depends on just how huge of an HTML file we're talking about here, but your mail server may simply not let you send things that large. This probably can not be addressed with simple programming; you're gonna have to come up with a creative solution, like sending through a different service or breaking up the message.


I believe that this is a problem with SMTP and sending that email/message. Try reducing the number of people you send a message to at one time. For example, if you are sending a message to 500 people at once, then maybe send the message to 50 different people at a time instead (sending the message ten times).


2 quick observations:

  1. "552 5.6.0 Headers too large"

    this is a SMTP error message. It's coming from your SMTP server, not your code. Your code is just bubbling it up.

  2. Headers are supposed to be seperated by "\r\n", not just "\n". Try fixing that part of your code.


I ran into this issue today. I resolved it by adding body tags to the HTML email.

Without those everything was going into the header.

MIME-Version: 1.0
Content-type: text/html
Subject: Nifty Report
<body>
<h1>some junk</h1>
</body>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜