Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Net::SMTP - Length limitation.

by the_0ne (Pilgrim)
on May 16, 2001 at 05:49 UTC ( [id://80786]=perlquestion: print w/replies, xml ) Need Help??

the_0ne has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have a question on a limitation I'm finding using Net::SMTP with string sizes over (around) 4000 characters. I have a small timesheet system that our company uses. It's written for the web and the way it works is all the data is kept in a sql server and then at the end of the day a automatic status report is generated and e-mailed to the user. These status reports can get pretty large because the boss likes to know details on everything we're doing, that's why I wrote it. It's been running for about a year and a half now with no problem then all of a sudden a status report failed to be sent the other day. First of all we're using Microsoft's SMTP and I'm not sure if this is a Net::SMTP problem or Microsoft's SMTP, so please forgive me now if this is not Perl-related, but I'm really not sure and that's why I'm posting. I noticed that the reason this e-mail didn't get sent is because the $body of the email was so large that either Net::SMTP or Microsoft's SMTP service could not handle it. Is there a limit. It's certainly not anything special code-wise.

# Set the smtp variables. $server = "mysmtpserver"; $sender = "$userName\@mydomain.com"; $addr = "$userName\@mydomain.com"; $subject = $cgi->param('subject'); $body = $cgi->param('EmailBody'); $body =~ s/\r\n/\n/g; my $smtp = Net::SMTP->new($server); $smtp->mail($sender); $smtp->to($addr); $smtp->data(); $smtp->datasend("From: $sender\n"); $smtp->datasend("To: $addr\n"); $smtp->datasend("Subject: Status Report $subject_date\n"); $smtp->datasend("$body\n");
That's not the full code, but the jist of the Net::SMTP code. The way I know that it fails over around 4000 chars is I have some code to split the $body into 3000 character strings with newlines at the end and that works fine. Now pretend that the $body var is at least 4500 characters. The mail will get stuck in the BADMAIL with this error...

This is a MIME-formatted message. Portions of this message may be unreadable without a MIME-capable mail program.

Again, I'm not sure if this is even a Perl problem, so excuse my ignorance if it's not Perl-related at all.

Replies are listed 'Best First'.
Re: Net::SMTP - Length limitation.
by mpolo (Chaplain) on May 16, 2001 at 10:34 UTC
    I suspect your problem may be that you are not sending a blank line between the header and the body, so your whole body is being sucked into the header and confusing either the SMTP server or the user agent. I think this is why it decided it was MIME-formatted as well, even though you have not generated a Content-type.

    Try changing your second-to-last line to:

    $smtp->datasend("Subject: Status Report $subject_date\n\n");
    There may well be a limit to how much data you can send with no newlines embedded, but I don't think the actual length of the string itself matters as long as it's divided up by newlines every so often (about 6 lines of text for some user agents I've used). I've successfully used Net::SMTP to send a packet of 20 encoded pngs all sucked into one string, though so I know the string can be long.
      That's exactly what I'm finding. That's the work-around I found. I have the string split up into 3000 character chunks with a newline after each. That works, but when I remove the split, the mail fails.

      The reason I'm thinking this way also is I took the string that it had trouble with and copied it into a text editor and even the text editor couldn't handle it. Had to be broken up. So, I'm thinking this is a just a limitation that I'm going to have to code for. Which is fine but I wanted to make sure it was and not something stupid I'm doing.
Re: Net::SMTP - Length limitation.
by eejack (Hermit) on May 16, 2001 at 07:43 UTC
    I may be way off on this, but it appears you are getting the information to be mailed through some sort of web form using CGI.pm.

    It is possible the message body portion could be coming in *incomplete* and that could be messing up the works. I would try it temporarily assigning your body variable to some text of about the same size, but not brought in from a webform.

    Perhaps reading it from a file or just setting it directly in the script to try it out.

    The reason why I mention this is I had a similar problem (putting text into a database) where it blew up when the amount of input was around 45K.

    There are two places that would be (or could be) limiting the amount of data you can post. One is the webserver itself, and where that setting might be, and whether or not it can be adjusted depends on the webserver itself. The other is in the $CGI::POST_MAX setting of CGI.pm for which you might find useful information here

    EEjack

      4K sounds like around the number that a form using GET might get cut-off at... you might wanna change the web-form's method to a POST if it isn't already.
        Funny you say that because that's almost exactly the limit that I'm being cut off at. But problem there is I'm using POST not GET. I just think it's a limit I'm going to have to deal with. My reply below shows that I'm also having trouble if I take that line that's causing the failure and copy it into a text editor. The text editor can't handle it over 4K either. Once I split it into 3000 char chunks, it works fine. So, must just be a limitation I'm going to have to handle.
      hmmmmmm, sounds sensible enough. I was just checking before I hit the sack so I'll try this in the morning and post tomorrow if that does seem to be the problem.

      Thanks for the reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://80786]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-20 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found