gpt4 book ai didi

email - 如何使用 Delphi 和 Synapse 一次向多个收件人发送电子邮件?

转载 作者:行者123 更新时间:2023-12-03 15:29:06 24 4
gpt4 key购买 nike

拜托,我已经尝试解决这个“问题”超过 12 个小时了……几乎快要疯了!我认为使用 Delphi 和 Synapse ( http://synapse.ararat.cz ) 不可能同时向多个收件人(目的地)发送相同的电子邮件。请有人告诉我我错了:)

嗯,我有一个 sEmail 变量,我在其中获取用分号 (;) 分隔的电子邮件,就像这样:

sEmails := 'email1@test.com.br;email2@teste.com.br';

这是我正在使用的代码:

dSMTP := TSMTPSend.Create;
dSMsg := TMimeMess.Create;
Try
With dSMsg, Header Do
Begin
Date := Now;
Priority := mp_Normal;
CharsetCode := ISO_8859_1;
From := 'email@gmail.com';
ToList.Delimiter := ';';
ToList.DelimitedText := sEmails;
Subject := 'Message Subject';
dPart := AddPartMultipart('mixed', nil);
AddPartHTML('<h1>Message Text</h1>', dPart);
EncodeMessage;
end;
With dSMTP Do
Begin
TargetHost := 'smtp.gmail.com';
TargetPort := '587';
AutoTLS := True;
UserName := 'email@gmail.com';
Password := 'password';
Try
If Login Then
Begin
If MailFrom('email@gmail.com', Length('email@gmail.com')) Then
If MailTo(sEmails) Then MailData(dSMsg.Lines);
Logout;
end;
Except
On E: Exception Do ShowMessage(E.Message);
end;
end;
Finally
dSMsg.Free;
dSMTP.Free;
end;

我已经尝试过这样的:

If Login Then
Begin
If MailFrom('email@gmail.com', Length('email@gmail.com')) Then
If MailTo(dSMsg.Header.ToList[0]) Then MailData(dSMsg.Lines);
Logout;
end;

...但是只发送了第一封电子邮件:(即使将其余电子邮件添加到 Header.CCList 中。

在另一个测试中,我尝试将点分号更改为逗号(,),但出现同样的问题...

拜托,拜托,有人可以告诉我我做错了什么吗?

谢谢!

最佳答案

根据documentation for SendTo :

Send "Maildata" (text of e-mail without any SMTP headers!) from "MailFrom" e-mail address to "MailTo" e-mail address with "Subject". (If you need more then one receiver, then separate their addresses by comma).

所以像这样的东西应该起作用(但见下文,因为它显然不起作用):

sEMails := 'joe@gmail.com,fred@gmail.com,mary@gmail.com';
....

if MailTo(sEMails) then
MailData(dSMsg.Lines);

似乎没有办法在 SMTPSend 组件中正确设置多个电子邮件地址。您必须单独发送每个。不过,您可以比自己解析地址更容易,因为您已经将它们添加到代码前面的 dSMsg.Header.ToList 中:

// Declare i as an integer variable, and post all the send to addresses
// one at a time to the MailTo() function
for i := 0 to dSMsg.Header.ToList.Count - 1 do
MailTo(dMsg.Header.ToList[i]);

// Now send the mail body
MailData(dSMsg.Lines)

IMO,Synapse SMTP 支持级别太低,无法轻松使用,除非您出于某种原因特别需要该低级别支持。 Indy(预装了 Delphi)和 ICS提供更简单的 SMTP 实现,都支持文本和 HTML 电子邮件以及 MIME 编码的附件,并且都支持使用 gmail 所需的 TLS。

关于email - 如何使用 Delphi 和 Synapse 一次向多个收件人发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15604243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com