delphi 发送html邮件,delphi - Send Email in HTML Format - Stack Overflow

本文探讨了通过MAPI接口从应用程序中发送HTML格式邮件的方法。作者尝试使用Delphi编写了一个示例程序来实现这一功能,但遇到了兼容性和实现难题。尽管MSDN指出MAPI可能不适合发送HTML邮件,作者还是希望能找到一种较为独立于具体邮件客户端的解决方案。

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

Delphi2010 实现邮件附件收发功能 TIdPOP3组件简介 TIdPOP3 是用来接收邮件服务器的邮件信息到用户端的一个组件。它实现了RFC 1939协议。 在使用TIdPOP3组件时需设置它的几个成员属性。 Host :指定邮件服务器,一般为pop3邮件服务器的地址,如 pop3.126.com。 Username :用户名,也就是邮箱名,如billanking2002@126.com。 Password :邮箱密码,在进行收发邮件时组件需要凭密码进行登录。 其它成员属性 Connected:返回它与邮件服务器的连接状态,这true表示已经连接。 CheckMessages:邮件数,如果连接服务器成功,则可以获得服务器端的邮件数。 成员函数 procedure Connect(const ATimeout: Integer = IdTimeoutDefault); 与服务器连接函数。参数为无效连接时等待的毫秒数。 function RetrieveHeader(const MsgNum: Integer; AMsg: TIdMessage): Boolean; 接收邮件头信息,它有两个参数,MsgNum表示在接收第几个邮件,从1开始,AMsg为邮件消息组件实例。 function Retrieve(const MsgNum: Integer; AMsg: TIdMessage): Boolean; 接收邮件主体信息,它与 RetrieveHeader的参数是一样的。接收的邮件内容将保存在AMsg中。 function Delete(const MsgNum: Integer): Boolean; 删除邮件服务器中第几个邮件。从1开始。 procedure Disconnect; override; 关闭连接。 TIdMessage组件简介 TIdMessage用来支持邮件消息协议,如POP3,SMTP,NNTP等。TIdMessage支持多用途Internet邮件扩展(MIME)协议。 常用的TIdMessage的属性: Subject:邮件主题,这个字符串经过BASE64编码的。所以在使用时需对它进行解码。 MessageParts:这是TIdMessageParts类的一个实例,它用来存储邮件的信息。如邮件内容及附件信息。在进行解析时需要判断它是否为附件或文本,如果为附件时,其文件名是经过BASE64编码的。判断常量分别为TIdText , TIdAttachment。 Body:这是个字符串列表,包含构成该邮件的正文内容。 Form:发送邮件者的地址信息。 Recipients:收件人地址信息。 BccList:抄送地址列表。 CharSet:指示邮件信息中使用的字符集。 ContentType:指定MIME媒体数据类型,描述正文中包含的数据,使用户代理决定如何显示数据,常用的有text/html,text/xml。 TIdSMTP组件简介 TIdSMTP是TIdMessageClient派生出的一个简单邮件传输协议和SMTP客户端。 它的主要功能是发送邮件信息。 常用的属性: Host :SMTP邮件服务器的地址,如smtp.126.com。它与上面的POP3地址不一样。 AuthenticationType:服务器认证类型,它有atNone,atLogin两种,即不需要认证和需要凭用户名和密码进行认证。 Username:用户名,这里与TIdPOP3 有点不一样,即它不需要后缀,如billanking2002 Password:邮箱登录密码。如果AuthenticationType设置了atLongin则必须设置密码和用户名。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值