procedure SendMail(sl : TStringlist);
var TextPart : TIDText;
Attachment : TIdAttachmentfile;
SendFile,
Body : string;
SentMsg : Tidmessage;
idSMTP1 : TidSMTP;
MemFile : TStrings;
begin
idSMTP1 := TidSMTP.Create(nil);
SentMsg := TIDMessage.Create(nil);
SendFile := settings.DirExport + '\' + sl.Values['xml'];
idSMTP1.Host := settings.SMTPhost;
if settings.SMTPUser > '' then
begin
idSMTP1.Username := settings.SMTPUser;
idSMTP1.Password := settings.SMTPWachtwoord;
end;
MemFile := TStringlist.Create;
// idSMTP1.Password:=your password;
try
with SentMsg do
begin
Clear;
IsEncoded := True ;
CharSet := 'iso-8859-1';
Encoding := meMIME;
ContentType := 'multipart/mixed';
Subject := sl.Values['bericht'] + ':' + sl.Values['leverancier'];
Body.Clear;
BccList.Clear;
//setup idmessage parameters
From.address := settings.Afzender;
Recipients.EMailAddresses := sl.Values['email'];
end;
TextPart := TIdText.Create(SentMsg.MessageParts, nil);
TextPart.ContentType := 'text/plain';
TextPart.Body.Text := '';
Attachment := TIdAttachmentfile.Create(SentMsg.MessageParts,SendFile);
Attachment.ContentDisposition := 'attachment';
Attachment.ContentType := 'text/xml';
Attachment.FileName := ExtractFileName(SendFile);
MemFile.LoadFromFile(SendFile);
Body := MemFile.Text;
//send the message
Memo1.Lines.Add('[VERZENDEN]');
Memo1.Lines.Add(format('%-10s : %-25s',['Verzend',datetostr(Now) + ' ' + timetostr(Now)]));
Memo1.Lines.Add(format('%-10s : %-30s',['Ontvanger',SentMsg.Recipients.EMailAddresses]));
Memo1.Lines.Add(format('%-10s : %-30s',['Subject',SentMsg.Subject]));
Memo1.Lines.Add('');
try
idSMTP1.Connect;
idSMTP1.send(SentMsg);
except on E: EIdSMTPReplyError do
ShowMessage(E.Message);
end;
finally
//disconnect from server
if IdSMTP1.Connected then
IdSMTP1.Disconnect;
SaveMessage(1,0, Body, SentMsg);
Attachment.Free;
TextPart.Free;
SentMsg.Free;
idSMTP1.Free;
Memfile.free;
end;
end;
Bookmarks