Using cnSMTPConnection to send an email

For questions and postings not covered by the other forums
Rich Cassell
Posts: 77
Joined: Mon Aug 24, 2009 11:22 pm
Location: Nottinghamshire, UK

Using cnSMTPConnection to send an email

Postby Rich Cassell » Fri Mar 16, 2012 11:13 pm

Hi all,

In our system we use the cnSMTPConnection class in a number of places to send "automatic" emails when something occurs. This has always worked sufficiently for the emails that we send, however, we now have a requirement to send an email where the message length is greater than 1000 characters, and it turns out that this is a problem...

The error i am getting is "100007 Undefined message number - CnSmtpConnection::validateASCIIMessage One of the message lines exceeds 1000 characters". I can't find any documentation on this class (though i am sure it must be somewhere) so i'm unsure as to how to force the email to be spread over more than one message line.

Has anybody else used this method to send an email of greater length? Or, is there a better way for me to achieve this. The email sending should need no manual intervention at all.

The bare-bones code i'm using for this is:

Code: Select all

vars conn : CnSmtpConnection; begin app.cnActivateKarmaControl(Cn_Fat_Client, null, null); create conn; self.beginNotification(conn, CnSmtpConnection.Completion_Event_Type, Response_Cancel, 0); conn.name := exchange server name; conn.sendFrom := emailFrom; conn.contentType := "html"; conn.sendTo := emailTo; conn.subject := "My email"; conn.message := Message needs to be > 1000 chars long conn.send; while not conn.completed do app.doWindowEvents(10); endwhile; epilog delete conn; end;
Any help would be greatly appreciated.

Rich

murray
Posts: 144
Joined: Fri Aug 14, 2009 6:58 pm
Location: New Plymouth, New Zealand

Re: Using cnSMTPConnection to send an email

Postby murray » Sat Mar 17, 2012 10:09 pm

I have seen this error (or similar) recently on that class when the body of the message was very long without any included new-line sequences (CrLf). I think this was because it was a long XML string or data dump. Normally, lines of text should be much shorter, and terminated with A CrLf sequence.

RFC 2822 states:
"There are two limits that this standard places on the number of characters in a line. Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF."
Murray (N.Z.)

User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

Re: Using cnSMTPConnection to send an email

Postby ghosttie » Sun Mar 18, 2012 1:12 am

Whenever we set CnSmtpConnection::message we do this:

Code: Select all

smtp.message := sMsg.enforceLineMaxLength(1000);
where String::enforceLineMaxLength is:

Code: Select all

enforceLineMaxLength(pI_LineMaxLength : Integer) : String; vars sRet, sLine : String; vlsa : VLSA; iLine : Integer; begin vlsa := split(CrLf); foreach iLine in 1 to vlsa.size do sLine := vlsa[iLine]; while sLine.length > pI_LineMaxLength do sRet := sRet & sLine[1 : pI_LineMaxLength] & CrLf; sLine := sLine[pI_LineMaxLength + 1 : end]; endwhile; sRet := sRet & sLine & CrLf; endforeach; return sRet; epilog delete vlsa; end;

String::split is a method that splits the receiver on the specified substring (in this case CrLf) and returns a VLSA (Variable Length String Array).
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

Rich Cassell
Posts: 77
Joined: Mon Aug 24, 2009 11:22 pm
Location: Nottinghamshire, UK

Re: Using cnSMTPConnection to send an email

Postby Rich Cassell » Tue Mar 20, 2012 12:57 am

Fantastic. Thanks alot guys. Works a treat :-)

Rich


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests

cron