procedure TfrmMessageEditor.CreateAndSendEmail(MailTo:
String;ExtSubject:
String;AttachmentPath:
string;BodyText:tstrings;contenttype:
string);
var
lTextPart: TIdText;
TechnikSignatur:
string;
begin
IdMsgSend:=TIdMessage.Create(
nil);
// Erstellen der Message
// Html Datei für individuelle HTML-Signaturen für diverse Techniker
TechnikSignatur:='
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
TechnikSignatur:=TechnikSignatur+'
</head><body><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="padding-left: 0px; padding-top: 0px; padding-bottom: 0px; padding-right: 0px;">';
TechnikSignatur:=TechnikSignatur+'
<span style="text-align: left; color: #000000; font-family: ''
Arial''
, sans-serif; font-size: 10pt; font-weight: bold"> ';
TechnikSignatur:=TechnikSignatur+trim(Main.Techniker_Anmelde_datasetVorname.Value)+'
'+trim(Main.Techniker_Anmelde_datasetName.Value)+'
</span><br><span style="text-align: left; margin-top: 0px; margin-bottom: 0px; color: #000000; font-family: ''
Arial''
, sans-serif;' ;
TechnikSignatur:=TechnikSignatur+'
font-weight: normal; font-size: 9pt;"> '+trim(Main.Techniker_Anmelde_datasetTitel.value)+'
</span><br></td></tr>';
//PDF Anhang generieren falls notwendig
if AttachmentPath<>'
'
then
begin
with TIdAttachmentFile.Create(IdMsgSend.MessageParts, AttachmentPath)
do
begin
FileName:= ExtSubject+'
.pdf';
end;
end;
//IDMessage konfigurieren
with IdMsgSend
do
begin
Body.Clear;
From.Text := Main.Techniker_Anmelde_datasetemail.Value;
ReplyTo.EMailAddresses := Main.Techniker_Anmelde_datasetemail.Value;
Recipients.EMailAddresses := MailTo;
{ To: header }
Subject := ExtSubject;
{ Subject: header }
Priority := TIdMessagePriority(cboPriority.ItemIndex);
{ Message Priority }
CCList.EMailAddresses := edtCC.Text;
{CC}
BccList.EMailAddresses := edtBCC.Text;
{BBC}
ReceiptRecipient.Text := Main.Techniker_Anmelde_datasetemail.Value;
end;
// Verschiedene MessageParts erstellen (wie auf http://www.indyproject.org/Sockets/Blogs/RLebeau/2005_08_17_A.EN.aspx beschrieben)
with TIdText.Create(IdMsgSend.MessageParts,
nil)
do begin
ContentType := '
multipart/related; type="multipart/alternative"';
end;
with TIdText.Create(IdMsgSend.MessageParts,
nil)
do begin
ContentType := '
multipart/alternative';
end;
with TIdText.Create(IdMsgSend.MessageParts,
nil)
do begin
Body.text:='
TestTestTest';
ContentType := '
text/plain';
end;
with TIdText.Create(IdMsgSend.MessageParts,
nil)
do begin
Body.Text := TechnikSignatur+Options_form.Option_datasetMailSignature.Value;
ContentType := '
text/html';
end;
if not FileExists(ExtractFilePath(ParamStr(0))+'
Logo.gif')
then
Options_form.DBAdvPicture1.Picture.SaveToFile(ExtractFilePath(ParamStr(0))+'
Logo.gif');
With TIdAttachmentFile.Create(IdMsgSend.MessageParts,ExtractFilePath(ParamStr(0))+'
Logo.gif' )
do begin
ContentID := '
image1';
ContentType := '
image/gif';
FileName := '
Logo.gif';
end;
IdMsgSend.ContentType := '
multipart/mixed';
{authentication settings}
SMTP.AuthType := satdefault;
{Simple Login}
SMTP.Username := Main.Techniker_Anmelde_datasetemail.Value;
SMTP.Password := Main.Techniker_Anmelde_datasetMailPasswort.Value;
{General setup}
SMTP.Host := main.Techniker_Anmelde_datasetsmtphost.Value;
SMTP.Port := main.Techniker_Anmelde_datasetsmtpport.value;
{now we send the message}
SMTP.Connect;
try
SMTP.Send(IdMsgSend);
finally
SMTP.Disconnect;
end;
IdMsgSend.free;
end;