Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

delphi - Send Email in HTML Format

At the moment we are using MAPI to send a plain text email from our application. We specify the dialog flag when the user invokes this function, so that the email will appear in their email client and they can then modify it and send it.

We would like to embelish the email and send it in an HTML format.
According to this link MSDN link MAPI is not sutiable for this http://support.microsoft.com/kb/268440

I have seen an article on ExpertsExchange that say you can use MAPI to do it but I can't get the example to work with Outlook (not tried anyother client yet)

procedure ShowMailDlg(ToName,Address,HTMLMessage: string);
var
    li: integer;
    lMessage: TMapiMessage;
    lRecipArray: array of TMapiRecipDesc;
    lREs: DWord;
begin
    SetLength(lRecipArray,1);
    lRecipArray[0].ulRecipClass:=MAPI_TO;
    lRecipArray[0].lpszName:=pChar(ToName);
    lRecipArray[0].lpszAddress:=pChar(Address);
    lMessage.ulReserved:=0;
    lMessage.lpszSubject:=nil;
    lMessage.lpszNoteText:=pChar(HTMLMessage);
    lMessage.lpszMessageType:= nil;//pChar('HTML');
    lMessage.lpszDateReceived:=nil;
    lMessage.lpszConversationID:=nil;
    lMessage.flFlags:=0;
    lMessage.lpOriginator:=nil;
    lMessage.nRecipCount:=length(lRecipArray);
    lMessage.lpRecips:=PMapiRecipDesc(lRecipArray);
    lMessage.nFileCount:=0;
    lMessage.lpFiles:=PMapiFileDesc(nil);
    lRes:=MapiSendMail(0, 0 , lMessage,MAPI_DIALOG, 0);
end;

Anyone have any ideas how I can do this. I could probably automate Outlook but I would like to keep it fairly independant of email client (hence MAPI)

Thanks

Update: thanks to everyone for the suggestions. The feature is question is not that heavily used, so asking the user to configure SMTP details is not really an option. I think we will just stick to the plain text email.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

MAPI doesn't support HTML formatted messages. From Microsoft : "Extended Messaging Application Programming Interface (MAPI) should not be used to generate HTML-formatted messages. As an alternative, consider using the Microsoft Outlook Object Model, CDONTS, CDOSYS, CDOEX, or a third-party SMTP control."

I would echo the comments about sending via Indy. I published a unit that works to send HTML messsages with Indy very simply here or feel free to write your own. If you really want to make the messages editable, try a combination of WPTools and Indy. WPTools has good support for HTML markup and then you can send the resulting message via Indy.

I don't have any experience with Synapse so I can't say how easy/hard it is with that project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...