delphi - Adding attachments to E-mail bound for Evernote E-mail address defeats HTML content type declaration with Indy TIdSMTP component -
i have delphi 6 application generates e-mails send evernote e-mail address, special e-mail address sending documents via e-mail stored automatically evernote account.
i have created html documents , sent them evernote e-mail address using indy 9.x tidsmtp component. set content-type 'text/html'. works fine long as don't add attachments e-mail. add attachment, generated e-mail makes evernote web interface interpret e-mail raw html. in other words, see raw html in document display area if had done "view-source" in browser, instead of seeing rendered web page. e-mail attachments adding avi file , wav file if matters. when add attachments both of them show @ bottom of e-mail in evernote web display area.
to repeat, don't add attachments document shows pretty web page in evernote web interface. if add attachments, see raw html. can suggest can try fix problem? have enclosed code use send generated document evernote e-mail address below. variable named body contains formatted html document.
update: sent e-mail non-evernote e-mail address see raw e-mail message. turns out adding attachments makes tidsmtp change content-type of first part of multi-part e-mail generates 'text/plain' despite fact set 'text/html' in code when create message. i'm going have @ indy source , see if can figure out going wrong.
function easysendemail( theidsmtp : tidsmtp; destemailaddress : string; subject : string; body : string; emailserversettings : temailserversettingsrecord; aryattachmentfilenames : tdynamicstringarray; connecttimeout_ms : integer; buseehlo : boolean; authlogintype : tauthenticationtype): boolean; var idmsg: tidmessage; aryattachments: tdynamicidattachmentarray; i: integer; begin aryattachments := nil; idmsg := nil; destemailaddress := trim(destemailaddress); if destemailaddress = '' raise exception.create('(tframeemailserversettings.easysendemail) destination e-mail address empty.'); subject := trim(subject); if subject = '' raise exception.create('(tframeemailserversettings.easysendemail) subject line empty.'); body := trim(body); if body = '' raise exception.create('(tframeemailserversettings.easysendemail) message body empty.'); try emailserversettings begin // build test message , send it. idmsg := tidmessage.create(nil); idmsg.recipients.emailaddresses := destemailaddress; { smtp servers require sending e-mail address user name authentication. however, if encounter 1 doesn't work way re-using authentication user name address not work. } idmsg.from.name := application_name_evermail; idmsg.from.address := user_name; idmsg.subject := subject; idmsg.body.text := body; idmsg.contenttype := 'text/html'; // idmsg.contenttype := 'text/plain'; theidsmtp.host := host; theidsmtp.username := user_name; theidsmtp.password := password; theidsmtp.port := port_number; // use ehlo method. theidsmtp.useehlo := true; // login method of authentication. theidsmtp.authenticationtype := atlogin; // add attachments. // >>> if comment out code below document shows // rendered web page in evernote web interface. // if uncomment , therefore add attachments, // document shows raw html. { if length(aryattachmentfilenames) > 0 begin setlength(aryattachments, length(aryattachmentfilenames)); := low(aryattachmentfilenames) high(aryattachmentfilenames) // add each attachment. aryattachments[i] := tidattachment.create(idmsg.messageparts, aryattachmentfilenames[i]); end; // if length(aryattachmentfilenames) > 0 } // connect desired smtp server. n second time-out. theidsmtp.connect(connecttimeout_ms); // send it. theidsmtp.send(idmsg); // if got here test succeeded. set flag // indicating current settings valid. result := true; end; // mergeeditswithoriginal theidsmtp.disconnect; if assigned(idmsg) idmsg.free; end; // try end;
your code not setting tidmessage correctly when attachments present. try instead:
function easysendemail( theidsmtp : tidsmtp; destemailaddress : string; thesubject : string; thebody : string; emailserversettings : temailserversettingsrecord; aryattachmentfilenames : tdynamicstringarray; connecttimeout_ms : integer; buseehlo : boolean; authlogintype : tauthenticationtype): boolean; var idmsg: tidmessage; i: integer; begin destemailaddress := trim(destemailaddress); if destemailaddress = '' raise exception.create('(tframeemailserversettings.easysendemail) destination e-mail address empty.'); thesubject := trim(thesubject); if thesubject = '' raise exception.create('(tframeemailserversettings.easysendemail) subject line empty.'); thebody := trim(thebody); if thebody = '' raise exception.create('(tframeemailserversettings.easysendemail) message body empty.'); idmsg := tidmessage.create(nil); try emailserversettings begin // build test message , send it. idmsg.recipients.emailaddresses := destemailaddress; { smtp servers require sending e-mail address user name authentication. however, if encounter 1 doesn't work way re-using authentication user name address not work. } idmsg.from.name := application_name_evermail; idmsg.from.address := user_name; idmsg.subject := thesubject; // add attachments. if length(aryattachmentfilenames) > 0 begin tidtext.create(idmsg.messageparts, nil) begin body.text := 'an html viewer required see message'; contenttype := 'text/plain'; end; tidtext.create(idmsg.messageparts, nil) begin body.text := thebody; contenttype := 'text/html'; end; // add each attachment. := low(aryattachmentfilenames) high(aryattachmentfilenames) tidattachment.create(idmsg.messageparts, aryattachmentfilenames[i]); idmsg.contenttype := 'multipart/mixed'; end else begin idmsg.body.text := thebody; idmsg.contenttype := 'text/html'; end; // if length(aryattachmentfilenames) > 0 theidsmtp.host := host; theidsmtp.username := user_name; theidsmtp.password := password; theidsmtp.port := port_number; // use ehlo method. theidsmtp.useehlo := true; // login method of authentication. theidsmtp.authenticationtype := atlogin; // connect desired smtp server. n second time-out. theidsmtp.connect(connecttimeout_ms); try // send it. theidsmtp.send(idmsg); // if got here test succeeded. set flag // indicating current settings valid. result := true; theidsmtp.disconnect; end; end; // emailserversettings idmsg.free; end; // try end;
Comments
Post a Comment