不得不最近使用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
'gt;
棘手的部分是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
'gt;
Note: Any code released into public domain. No attribution required.