delphi - Maximum length of message using Indy components -
i'm trying send message delphi-code use tidmessage. message consists of 2 parts: text/plain , text/html. have html-page template , large text need insert template (in special place marked ##text##). after merge template , text body of new message. send message (use tidmessage , tidsmtp), in result message contain second part of text. text have more 40,000 characters. when send message without html-tmplate (only large text) ok.
how can set length of message?
i tried set fidmessage.contenttransferencoding := 'quoted-printable' , fidsmtp.msglinelength := maxword; did not me.
thanks in advance.
here code:
var fsmtp: tidsmtp; fidmessage: tidmessage; idx: integer; i: integer; fidtext: tidtext; begin fsmtp := tidsmtp.create( nil ); fidmessage := tidmessage.create( nil ); try try fidmessage.extraheaders.clear; fidmessage.messageparts.clear; // attachments idx := 0 attachments.count - 1 tidattachment.create( fidmessage.messageparts, temailattachment( attachments.items[ idx ] ).flocaltemplatename ); fidmessage.from.text := ffrom; fidmessage.recipients.emailaddresses := fto; fidmessage.subject := fsubject; if (fhtmltemplatefilepath <> '') begin fidmessage.contenttype := 'multiparts/related; type="text/html"'; addattachements(fidmessage); // procedure added attachments fidtext := tidtext.create(fidmessage.messageparts, nil); fidtext.body.text := 'please view html version of email'; fidtext.contenttype := 'text/plain'; fidtext := tidtext.create(fidmessage.messageparts, nil); fidtext.body.text := fbody; fidtext.contenttype := 'text/html'; end else begin fidmessage.body.text := fbody; end; fidmessage.cclist.clear; fidmessage.receiptrecipient.text := ''; fsmtp.authenticationtype := fsmtpauthenticationtype; fsmtp.userid := fsmtpuserid; fsmtp.password := fsmtppassword; fsmtp.host := fsmtphost; fsmtp.port := fsmtpport; fsmtp.msglinelength := maxword; repeatretrycount := fsmtprepeatretrycount; fsmtp.connect; try fsmtp.send( fidmessage ); fsmtp.disconnect; end; except end; fsmtp.free; fidmessage.free; end; end; procedure addattachements(aidmessage: tidmessage); var lcid: integer; lfilename, lfileext, lsearchfolder: string; lsearchresult: tsearchrec; attachment: tidattachment; begin fhtmlcids.clear; lsearchfolder := extractfilepath(fhtmltemplatefilepath)+changefileext(extractfilename(fhtmltemplatefilepath),''); if (findfirst(lsearchfolder + '_*', fadirectory, lsearchresult)=0) or (findfirst(lsearchfolder + '.*', fadirectory, lsearchresult)=0) lsearchfolder := lsearchresult.name; findclose(lsearchresult); if findfirst(extractfilepath(fhtmltemplatefilepath)+lsearchfolder+'\*.*', faanyfile - fadirectory, lsearchresult)=0 begin repeat attachment := tidattachment.create(aidmessage.messageparts, extractfilepath(fhtmltemplatefilepath)+ lsearchfolder + '\' + lsearchresult.name); lcid := random(maxint); attachment.extraheaders.values['content-id'] := inttostr(lcid); lfilename := extractfilename(lsearchresult.name); lfileext := extractfileext(lsearchresult.name); if uppercase(lfileext) = '.xml' attachment.contenttype := 'text/xml' else if uppercase(lfileext) = '.png' attachment.contenttype := 'image/png' else if uppercase(lfileext) = '.thmx' attachment.contenttype := 'application/vnd.ms-officetheme' else if uppercase(lfileext) = '.jpg' attachment.contenttype := 'image/jpeg' else if uppercase(lfileext) = '.gif' attachment.contenttype := 'image/gif' else if uppercase(lfileext) = '.svg' attachment.contenttype := 'image/svg+xml' else if uppercase(lfileext) = '.tif' attachment.contenttype := 'image/tiff' else if uppercase(lfileext) = '.tiff' attachment.contenttype := 'image/tiff' else if uppercase(lfileext) = '.ico' attachment.contenttype := 'image/vnd.microsoft.icon' else if uppercase(lfileext) = '.bmp' attachment.contenttype := 'image/bmp' else if uppercase(lfileext) = '.css' attachment.contenttype := 'text/css' else if uppercase(lfileext) = '.js' attachment.contenttype := 'application/javascript' else if uppercase(lfileext) = '.jpeg' attachment.contenttype := 'image/jpeg' else if uppercase(lfileext) = '.wmz' attachment.contenttype := 'application/x-ms-wmz' else raise exception.createfmt('unknown file type "%s"', [lfileext]); fhtmlcids.addobject(lsearchfolder+'/'+lfilename, tobject(lcid)); fhtmlcids.addobject(urlencode(lsearchfolder+'/'+lfilename), tobject(lcid)); until findnext(lsearchresult)<>0; findclose(lsearchresult); end; fhtmlcids.sort; end;
tidmessage not impose limit on text length. else going on. guess not filling in tidmessage correctly. did not show addattachments() code, adding tidattachment objects before tidtext objects, , wrong, contenttype using. suggest read following blog article on indy's website proper structure of html email in tidmessage:
however, take notice of following warning:
unfortunately, indy 9 not handle plaintext+html+images scenerio should. indy 10 handles better...
you not using indy 10 (as evident fact passing filename tidattachment constructor - constructor moved new tidatttachmentfile class in indy 10).
also, fyi, not need set msglinelength property, has no effect whatsoever (in fact, did not know indy still had property - dead property used tidmessageclient.writefoldedline(), dead method not used anything).
Comments
Post a Comment