delphi 发送html邮件,Delphi下html编辑器,像foxmail或者Outlook的邮件编辑器一样 能够保存为单一文件如 mht,eml (200分)...

话题3631014的标题是: Delphi下html编辑器,像foxmail或者Outlook的邮件编辑器一样 能够保存为单一文件如 mht,eml (200分)

分类:数据库-C/S型 sdie (2006-11-24 10:40:00)

我在论坛上搜了好久,一直没有搜索到理想的解决方式。

我希望能够实现html的简单编辑,例如插入图片,改变字体的样式、颜色,插入表格等等

并且将所有的文件保存为一个文件,如保存为mht,并且可以对存在的mht进行读取,

对此,foxmail和outlook做的比较好,因此希望大家能够帮助。

应该有不少的朋友遇到过此问题,希望和大家共同讨论学习。

我的信箱是:279197511@163.com dingbaosheng (2006-11-24 15:16:29)

编辑 HTML 很EASY

自己用TWEBBROWERSE写 也可以用三方控件

保存成MHT文件 可以做到 但是要再读进来修改 就麻烦了 sdie (2006-11-25 10:34:50)

谁有例子呀 能不能发一份 Email: 279197511@163.com 大傻子 (2006-11-27 13:28:53)

这两个例子我都测试过了,不过都没有实现保存为mht的文件,

是不是下载一个类似于Email2000的控件可以呀,我在网上找了好久也没找到 0桁骀 (2006-11-27 23:12:36)

将网页保存为mht文件~~

(*//

标题:将网页保存为mht文件

说明:接口只定义需要使用的部分,如要研究请参考其他文档

设计:Zswang

支持:wjhu111@21cn.com

日期:2004-01-05

//*)

///Begin Source

uses ComObj;

///Begin 接口定义

// Constants for enum SaveOptionsEnum

type

SaveOptionsEnum = TOleEnum;

const

adSaveCreateNotExist = $00000001;

adSaveCreateOverWrite = $00000002;

// Constants for enum CdoMHTMLFlags

type

CdoMHTMLFlags = TOleEnum;

const

cdoSuppressNone = $00000000;

cdoSuppressImages = $00000001;

cdoSuppressBGSounds = $00000002;

cdoSuppressFrames = $00000004;

cdoSuppressObjects = $00000008;

cdoSuppressStyleSheets = $00000010;

cdoSuppressAll = $0000001F;

// Constants for enum StreamTypeEnum

type

StreamTypeEnum = TOleEnum;

const

adTypeBinary = $00000001;

adTypeText = $00000002;

// Constants for enum LineSeparatorEnum

type

LineSeparatorEnum = TOleEnum;

const

adLF = $0000000A;

adCR = $0000000D;

adCRLF = $FFFFFFFF;

// Constants for enum ObjectStateEnum

type

ObjectStateEnum = TOleEnum;

const

adStateClosed = $00000000;

adStateOpen = $00000001;

adStateConnecting = $00000002;

adStateExecuting = $00000004;

adStateFetching = $00000008;

// Constants for enum ConnectModeEnum

type

ConnectModeEnum = TOleEnum;

const

adModeUnknown = $00000000;

adModeRead = $00000001;

adModeWrite = $00000002;

adModeReadWrite = $00000003;

adModeShareDenyRead = $00000004;

adModeShareDenyWrite = $00000008;

adModeShareExclusive = $0000000C;

adModeShareDenyNone = $00000010;

adModeRecursive = $00400000;

// Constants for enum StreamOpenOptionsEnum

type

StreamOpenOptionsEnum = TOleEnum;

const

adOpenStreamUnspecified = $FFFFFFFF;

adOpenStreamAsync = $00000001;

adOpenStreamFromRecord = $00000004;

// Constants for enum StreamWriteEnum

type

StreamWriteEnum = TOleEnum;

const

adWriteChar = $00000000;

adWriteLine = $00000001;

stWriteChar = $00000000;

stWriteLine = $00000001;

// Constants for enum CdoDSNOptions

type

CdoDSNOptions = TOleEnum;

const

cdoDSNDefault = $00000000;

cdoDSNNever = $00000001;

cdoDSNFailure = $00000002;

cdoDSNSuccess = $00000004;

cdoDSNDelay = $00000008;

cdoDSNSuccessFailOrDelay = $0000000E;

// Constants for enum CdoReferenceType

type

CdoReferenceType = TOleEnum;

const

cdoRefTypeId = $00000000;

cdoRefTypeLocation = $00000001;

type

IBodyPart = interface(IDispatch)

['{CD000021-8B95-11D1-82DB-00C04FB1625D}']

end;

IBodyParts = interface(IDispatch)

['{CD000023-8B95-11D1-82DB-00C04FB1625D}']

end;

_Collection = interface(IDispatch)

['{00000512-0000-0010-8000-00AA006D2EA4}']

end;

Fields15 = interface(_Collection)

['{00000506-0000-0010-8000-00AA006D2EA4}']

end;

Fields20 = interface(Fields15)

['{0000054D-0000-0010-8000-00AA006D2EA4}']

end;

Fields = interface(Fields20)

['{00000564-0000-0010-8000-00AA006D2EA4}']

end;

IDataSource = interface(IDispatch)

['{CD000029-8B95-11D1-82DB-00C04FB1625D}']

end;

type

_Stream = interface(IDispatch)

['{00000565-0000-0010-8000-00AA006D2EA4}']

function Get_Size: Integer; safecall;

function Get_EOS: WordBool; safecall;

function Get_Position: Integer; safecall;

procedure Set_Position(pPos: Integer); safecall;

function Get_Type_: StreamTypeEnum; safecall;

procedure Set_Type_(ptype: StreamTypeEnum); safecall;

function Get_LineSeparator: LineSeparatorEnum; safecall;

procedure Set_LineSeparator(pLS: LineSeparatorEnum); safecall;

function Get_State: ObjectStateEnum; safecall;

function Get_Mode: ConnectModeEnum; safecall;

procedure Set_Mode(pMode: ConnectModeEnum); safecall;

function Get_Charset: WideString; safecall;

procedure Set_Charset(const pbstrCharset: WideString); safecall;

function Read(NumBytes: Integer): OleVariant; safecall;

procedure Open(Source: OleVariant; Mode: ConnectModeEnum; Options: StreamOpenOptionsEnum;

const UserName: WideString; const Password: WideString); safecall;

procedure Close; safecall;

procedure SkipLine; safecall;

procedure Write(Buffer: OleVariant); safecall;

procedure SetEOS; safecall;

procedure CopyTo(const DestStream: _Stream; CharNumber: Integer); safecall;

procedure Flush; safecall;

procedure SaveToFile(const FileName: WideString; Options: SaveOptionsEnum); safecall;

end;

IConfiguration = interface(IDispatch)

['{CD000022-8B95-11D1-82DB-00C04FB1625D}']

end;

IMessage = interface(IDispatch)

['{CD000020-8B95-11D1-82DB-00C04FB1625D}']

function Get_BCC: WideString; safecall;

procedure Set_BCC(const pBCC: WideString); safecall;

function Get_CC: WideString; safecall;

procedure Set_CC(const pCC: WideString); safecall;

function Get_FollowUpTo: WideString; safecall;

procedure Set_FollowUpTo(const pFollowUpTo: WideString); safecall;

function Get_From: WideString; safecall;

procedure Set_From(const pFrom: WideString); safecall;

function Get_Keywords: WideString; safecall;

procedure Set_Keywords(const pKeywords: WideString); safecall;

function Get_MimeFormatted: WordBool; safecall;

procedure Set_MimeFormatted(pMimeFormatted: WordBool); safecall;

function Get_Newsgroups: WideString; safecall;

procedure Set_Newsgroups(const pNewsgroups: WideString); safecall;

function Get_Organization: WideString; safecall;

procedure Set_Organization(const pOrganization: WideString); safecall;

function Get_ReceivedTime: TDateTime; safecall;

function Get_ReplyTo: WideString; safecall;

procedure Set_ReplyTo(const pReplyTo: WideString); safecall;

function Get_DSNOptions: CdoDSNOptions; safecall;

procedure Set_DSNOptions(pDSNOptions: CdoDSNOptions); safecall;

function Get_SentOn: TDateTime; safecall;

function Get_Subject: WideString; safecall;

procedure Set_Subject(const pSubject: WideString); safecall;

function Get_To_: WideString; safecall;

procedure Set_To_(const pTo: WideString); safecall;

function Get_TextBody: WideString; safecall;

procedure Set_TextBody(const pTextBody: WideString); safecall;

function Get_HTMLBody: WideString; safecall;

procedure Set_HTMLBody(const pHTMLBody: WideString); safecall;

function Get_Attachments: IBodyParts; safecall;

function Get_Sender: WideString; safecall;

procedure Set_Sender(const pSender: WideString); safecall;

function Get_Configuration: IConfiguration; safecall;

procedure _Set_Configuration(const pConfiguration: IConfiguration); safecall;

procedure Set_Configuration(const pConfiguration: IConfiguration); safecall;

function Get_AutoGenerateTextBody: WordBool; safecall;

procedure Set_AutoGenerateTextBody(pAutoGenerateTextBody: WordBool); safecall;

function Get_EnvelopeFields: Fields; safecall;

function Get_TextBodyPart: IBodyPart; safecall;

function Get_HTMLBodyPart: IBodyPart; safecall;

function Get_BodyPart: IBodyPart; safecall;

function Get_DataSource: IDataSource; safecall;

function Get_Fields: Fields; safecall;

function Get_MDNRequested: WordBool; safecall;

procedure Set_MDNRequested(pMDNRequested: WordBool); safecall;

function AddRelatedBodyPart(const URL: WideString; const Reference: WideString;

ReferenceType: CdoReferenceType; const UserName: WideString;

const Password: WideString): IBodyPart; safecall;

function AddAttachment(const URL: WideString; const UserName: WideString;

const Password: WideString): IBodyPart; safecall;

procedure CreateMHTMLBody(const URL: WideString; Flags: CdoMHTMLFlags;

const UserName: WideString; const Password: WideString); safecall;

function Forward: IMessage; safecall;

procedure Post; safecall;

function PostReply: IMessage; safecall;

function Reply: IMessage; safecall;

function ReplyAll: IMessage; safecall;

procedure Send; safecall;

function GetStream: _Stream; safecall;

function GetInterface(const Interface_: WideString): IDispatch; safecall;

property BCC: WideString read Get_BCC write Set_BCC;

property CC: WideString read Get_CC write Set_CC;

property FollowUpTo: WideString read Get_FollowUpTo write Set_FollowUpTo;

property From: WideString read Get_From write Set_From;

property Keywords: WideString read Get_Keywords write Set_Keywords;

property MimeFormatted: WordBool read Get_MimeFormatted write Set_MimeFormatted;

property Newsgroups: WideString read Get_Newsgroups write Set_Newsgroups;

property Organization: WideString read Get_Organization write Set_Organization;

property ReceivedTime: TDateTime read Get_ReceivedTime;

property ReplyTo: WideString read Get_ReplyTo write Set_ReplyTo;

property DSNOptions: CdoDSNOptions read Get_DSNOptions write Set_DSNOptions;

property SentOn: TDateTime read Get_SentOn;

property Subject: WideString read Get_Subject write Set_Subject;

property To_: WideString read Get_To_ write Set_To_;

property TextBody: WideString read Get_TextBody write Set_TextBody;

property HTMLBody: WideString read Get_HTMLBody write Set_HTMLBody;

property Attachments: IBodyParts read Get_Attachments;

property Sender: WideString read Get_Sender write Set_Sender;

property Configuration: IConfiguration read Get_Configuration write _Set_Configuration;

property AutoGenerateTextBody: WordBool read Get_AutoGenerateTextBody write Set_AutoGenerateTextBody;

property EnvelopeFields: Fields read Get_EnvelopeFields;

property TextBodyPart: IBodyPart read Get_TextBodyPart;

property HTMLBodyPart: IBodyPart read Get_HTMLBodyPart;

property BodyPart: IBodyPart read Get_BodyPart;

property DataSource: IDataSource read Get_DataSource;

property Fields: Fields read Get_Fields;

property MDNRequested: WordBool read Get_MDNRequested write Set_MDNRequested;

end;

const

CLASS_Message: TGUID = '{CD000001-8B95-11D1-82DB-00C04FB1625D}';

CLASS_Configuration: TGUID = '{CD000002-8B95-11D1-82DB-00C04FB1625D}';

///End 接口定义

procedure SaveWholePage(mURL: string; mFileName: TFileName);

var

vMessage: IMessage;

vConfiguration: IConfiguration;

vStream: _Stream;

begin

vMessage := CreateComObject(CLASS_Message) as IMessage;

vConfiguration := CreateComObject(CLASS_Configuration) as IConfiguration;

try

vMessage.Configuration := vConfiguration;

vMessage.CreateMHTMLBody(mURL, cdoSuppressAll, '', '');

vStream := vMessage.GetStream;

vStream.SaveToFile(mFileName, adSaveCreateOverWrite);

finally

vMessage := nil;

vConfiguration := nil;

vStream := nil;

end;

end;

///End Source

//Example

procedure TForm1.Button1Click(Sender: TObject);

begin

SaveWholePage('http://www.eping.net/fourm/', 'c:\temp\temp.mht');

end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值