10-19-2021, 01:59 PM
(This post was last modified: 10-19-2021, 02:32 PM by scampsmith.)
Thanks, everyone!
Your responses helped me get it working on first try!
Using the TIdMessageBuilderHtml makes it super simple, unlike the demo project, which is what I based by original code from.
Thanks!
--Stanwood
Ooops! Spoke too soon! Then email looks better, but now the file is not actually transmitted. Even looking at the 'raw content' shows no MIM encoding, just the headers. I'm sure I'm still missing a step, since the original code I was using actualy did include the MIM encoding.
oMsg := TIdMessage.Create;
try
oMsg.Date := Now;
oMsg.FromList.EMailAddresses := Self.edtFrom.text
oMsg.Subject := edtSubJect.Text;
oMsg.Recipients.EMailAddresses := edtTo.Text;
oMsgBldr := TIdMessageBuilderHtml.Create;
try
oMsgBldr.Html.Text := 'HTML goes here!';
OMsgBldr.PlainText.Text := Memo1.Text;
for j := 0 to lbFiles.Items.Count-1 do
oMsgBldr.Attachments.Add(lbFiles.Items[j]);
oMsgBldr.FillMessage(oMsg);
finally
oMsgBldr.Free;
end;
SMTP.AuthType := satDefault; {Simple Login}
SMTP.Username := 'order@hiemstraoptical.com'; // SmtpServerUser;
SMTP.Password := 'orderdept'; // SmtpServerPassword;
{General setup}
SMTP.Host := Self.SmtpServerName;
SMTP.Port := 25; // SmtpServerPort;
{now we send the message}
SMTP.Connect;
try
SMTP.Send(oMsg);
finally
SMTP.Disconnect;
end;
finally
oMsg.Free;
end;
Your responses helped me get it working on first try!
Using the TIdMessageBuilderHtml makes it super simple, unlike the demo project, which is what I based by original code from.
Thanks!
--Stanwood
Ooops! Spoke too soon! Then email looks better, but now the file is not actually transmitted. Even looking at the 'raw content' shows no MIM encoding, just the headers. I'm sure I'm still missing a step, since the original code I was using actualy did include the MIM encoding.
oMsg := TIdMessage.Create;
try
oMsg.Date := Now;
oMsg.FromList.EMailAddresses := Self.edtFrom.text
oMsg.Subject := edtSubJect.Text;
oMsg.Recipients.EMailAddresses := edtTo.Text;
oMsgBldr := TIdMessageBuilderHtml.Create;
try
oMsgBldr.Html.Text := 'HTML goes here!';
OMsgBldr.PlainText.Text := Memo1.Text;
for j := 0 to lbFiles.Items.Count-1 do
oMsgBldr.Attachments.Add(lbFiles.Items[j]);
oMsgBldr.FillMessage(oMsg);
finally
oMsgBldr.Free;
end;
SMTP.AuthType := satDefault; {Simple Login}
SMTP.Username := 'order@hiemstraoptical.com'; // SmtpServerUser;
SMTP.Password := 'orderdept'; // SmtpServerPassword;
{General setup}
SMTP.Host := Self.SmtpServerName;
SMTP.Port := 25; // SmtpServerPort;
{now we send the message}
SMTP.Connect;
try
SMTP.Send(oMsg);
finally
SMTP.Disconnect;
end;
finally
oMsg.Free;
end;