拜托,我现在试图解决这个“问题”超过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 forSendTo:
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.
