delphi发送邮件(附件+内嵌资源)源码分析

来源:互联网 发布:湖南传奇网络 编辑:程序博客网 时间:2024/06/14 00:53

    1.无附件

    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    Body.Text := 'plain text goes here';
    ContentType := 'text/plain';
    end;
    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    Body.Text := 'HTML goes here';
    ContentType := 'text/html';
    end;
    IdMessage1.ContentType := 'multipart/alternative';





    2.只有附件

    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    ContentType := 'multipart/alternative';
    end;
    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    Body.Text := 'plain textgoes here';
    ContentType := 'text/plain';
    ParentPart := 0;
    end;
    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    Body.Text := 'HTML goes here';
    ContentType := 'text/html';
    ParentPart := 0;
    end;
    with TIdAttachmentFile.Create(IdMessage1.MessageParts, 'c:\folder\archive.zip') do begin
    ContentType := 'application/x-zip-compressed';
    FileName := 'archive.zip';
    end;
    IdMessage1.ContentType := 'multipart/mixed';





    3.只有内嵌资源

    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    ContentType := 'multipart/alternative';
    end;
    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    Body.Text := 'plain textgoes here';
    ContentType := 'text/plain';
    ParentPart := 0;
    end;
    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    Body.Text := 'HTML goes here';
    ContentType := 'text/html';
    ParentPart := 0;
    end;
    with TIdAttachmentFile.Create(IdMessage1.MessageParts, 'c:\folder\image1.jpg') do begin
    ContentID := '12345';
    ContentType := 'image/jpeg';
    FileName := 'image1.jpg';
    end;
    with TIdAttachmentFile.Create(IdMessage1.MessageParts, 'c:\folder\image2.jpg') do begin
    ContentID := '56789';
    ContentType := 'image/jpeg';
    FileName := 'image2.jpg';
    end;
    IdMessage1.ContentType := 'multipart/related; type="multipart/alternative"';





    4.内嵌资源附件都有

    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    ContentType := 'multipart/related; type="multipart/alternative"';
    end;
    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    ContentType := 'multipart/alternative';
    ParentPart := 0;
    end;
    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    Body.Text := 'plain textgoes here';
    ContentType := 'text/plain';
    ParentPart := 1;
    end;
    with TIdText.Create(IdMessage1.MessageParts, nil) do begin
    Body.Text := 'HTML goes here';
    ContentType := 'text/html';
    ParentPart := 1;
    end;
    with TIdAttachmentFile.Create(IdMessage1.MessageParts, 'c:\folder\image1.jpg') do begin
    ContentID := '12345';
    ContentType := 'image/jpeg';
    FileName := 'image1.jpg';
    ParentPart := 0;
    end;
    with TIdAttachmentFile.Create(IdMessage1.MessageParts, 'c:\folder\image2.jpg') do begin
    ContentID := '56789';
    ContentType := 'image/jpeg';
    FileName := 'image2.jpg';
    ParentPart := 0;
    end;
    with TIdAttachmentFile.Create(IdMessage1.MessageParts, 'c:\folder\archive.zip') do begin
    ContentType := 'application/x-zip-compressed';
    FileName := 'archive.zip';
    end;
    IdMessage1.ContentType := 'multipart/mixed';

原创粉丝点击