How do I send an attachment in an HTML formatted email?
I managed to send an email using stmp.gmail.com in HTML format, but my email has an attachment. The attachment gets converted to a string, but I need it to be in the original file format.
Code:
with FIdSmtp do
begin
// Configure IdSMTP
end;
FIdMessage.Clear;
FIdMessage.MessageParts.Clear;
FIdMessage.From.Address := 'EmailRemetente';
FIdMessage.From.Name := 'Apelido';
FIdMessage.Subject := 'Assunto';
FIdMessage.Body.Text := 'Mensagem';
FIdMessage.Recipients.EMailAddresses := 'aEmailDestinatario'; //email destino
FIdMessage.BccList.EMailAddresses := StringReplace(Trim(BCCList.Text),#13#10,',',[rfReplaceAll]);
FIdMessage.ccList.EMailAddresses := StringReplace(Trim(CCList.Text),#13#10,',',[rfReplaceAll]);
FIdMessage.ContentType := 'text/html'; // set html format
_Anexo := TStringList.Create;
try
_Anexo.Text := aAnexos;
for i := 0 to _Anexo.Count - 1 do
TIdAttachmentFile.Create(FIdMessage.MessageParts,_Anexo.Strings[i]);
finally
_Anexo.Free
end;
FIdSmtp.Send(FIdMessage);
Can someone help me?
Read my blog on Indy's website, I discussed this subject in some detail:
HTML Messages
New HTML Message Builder class
With that in mind, try this:
Or this: