如何使用IdSMTP(Delphi)发送带有html-contetent的电子邮件?

前端之家收集整理的这篇文章主要介绍了如何使用IdSMTP(Delphi)发送带有html-contetent的电子邮件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如何使用带有html-contetent的Delphi的IdSMTP组件发送电子邮件

最佳答案
不得不最近使用Indy IdSmtp组件,遗憾的是这个问题没有很好的答案.我重新编写了我们的帮助函数,使用Indy(HTML和纯文本)发送电子邮件

样本用法

SendHtmlEmailIndy(
        'smtp.stackoverflow.com',//the SMTP server address
        'Spammy McSpamerson','spams@example.com',//From name,from e-mail address
        'joe@foo.net,jane@bar.net',//To addresses - comma separated
        'john@doe.net',//CC addresses - comma separated
        '',//BCC addresses - comma separated
        'Here is your sample spam e-mail',//Subject
        '

棘手的部分是Indy使发送HTML电子邮件变得困难.他们最终提供了一个TIdMessageBuilderHtml类来处理大部分繁琐的工作;但它远没有像SmtpClient类那样令人愉快.最后,你会依赖三个单位.

代码

procedure SendEmailIndy(
        const SMTPServer: string;
        const FromName,FromAddress: string;
        const ToAddresses: string; //comma "," separated list of e-mail addresses
        const CCAddresses: string; //comma "," separated list of e-mail addresses
        const BCCAddresses: string; //comma "," separated list of e-mail addresses
        const Subject: string;
        const EmailBody: string;
        const IsBodyHtml: Boolean; //verses Plain Text
        const Attachments: TStrings);
var
    smtp: TIdSMTP; // IdSmtp.pas
    msg: TidMessage; // IdMessage.pas
    builder: TIdCustomMessageBuilder; //IdMessageBuilder.pas
    s: string;
    emailAddress: string;
begin
{
    Sample usage:

    SendEmailIndy(
            'smtp.stackoverflow.com',//the SMTP server address
            'Spammy McSpamerson',from e-mail address
            'joe@foo.net,//To addresses - comma separated
            'john@doe.net',//CC addresses - comma separated
            '',//BCC addresses - comma separated
            'Here is your sample spam e-mail',//Subject
            '

Note: Any code released into public domain. No attribution required.

猜你在找的HTML相关文章