WebObjects 4: Preventing Line Breaks In WOSendMail

This article describes why linebreaks appear in electronic mail generated by the WOMailDelivery class and sent by WOSendMail, and how to reduce the occurrence of line breaks that can hurt the overall appearance of your plain text e-mails.
WebObjects 4 provides a class for generating and sending e-mail called WOMailDelivery. Behind the scenes WOMailDelivery invokes a tool called WOSendMail. To generate a plain text e-mail, you can add the WOExtensions framework to your project and add code like the following...

String theMailString =WOMailDelivery.sharedInstance().composePlainTextEmail(from, to, cc, subject, message, false);

where message represents the body of the e-mail. The message might be pre-defined, or it might be something a user enters into a WOTextfield on one of the pages of your WebObjects application. See the WOMailDelivery class description for information about the remaining parameters.

Your app would send the message with the following code:

WOMailDelivery.sharedInstance().sendMail( theMailString );

The resulting e-mail might wrap the lines of text at a seemingly arbitrary pre-chosen length. This can result in ugly line-wrapping for some e-mail clients. Some customers would prefer to eliminate this pre-chosen line length, so that their e-mail clients will wrap the lines based on window size.

According to the SMTP specification, the limit for line length should be 998 characters (leaving 2 characters for carriage return and linefeed). ( See http://freesoft.org/CIE/RFC/821/24.htm for more information). WOSendMail defaults to a line length of 76 characters. To change this default, simply add an entry to WOSendMail's defaults database. WOSendMail includes a "LineLength" user default. When the LineLength default is set to a positive integral value, the line wrapping occurs as directed by the user default. Type the following at a shell prompt:

defaults write WOSendMail LineLength 998

If you have problems, make sure the 'defaults' command is on your path. The executable should be located in $NEXT_ROOT/Library/Executables.

Note: Setting this user default will not prevent line-breaks for e-mails whose line lengths exceed 998 characters. E-mail messages with non-standard line lengths will display differently on different e-mail clients.

Published Date: Feb 18, 2012