According to the 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).
So something like this should work (but see below, because it doesn't apparently):
sEMails := 'joe@gmail.com,fred@gmail.com,mary@gmail.com';
....
if MailTo(sEMails) then
MailData(dSMsg.Lines);
It seems that there isn't a way to set multiple email addresses properly in the SMTPSend
component. You have to send each individually. You can, however, do it easier than parsing the addresses yourself, since you've already added them to dSMsg.Header.ToList
earlier in your code:
// 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, the Synapse SMTP support is too low level to use easily unless you specifically need that low level support for some reason. Both Indy (which comes with Delphi pre-installed) and ICS provide much easier implementation of SMTP
, both support both text and HTML emails and MIME-encoded attachments, and both support the TLS needed for working with gmail.