unit Mainform;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdMessage, IdSMTP, IdSSLOpenSSL, IdSASLLogin, IdSASLExternal,
IdUserPassProvider, IdSASL_CRAM_MD5, IdSASL_CRAM_SHA1, IdSASLPlain,
IdSASLSKey, IdSASLOTP, IdSASLAnonymous, IdAttachment, IdComponent,
IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase,
IdGlobal, IdTCPConnection, StdCtrls, IdText, IdAttachmentMemory;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
TCalendarData =
class
cdHost:
string;
//Strato: smtp.strato.de
cdAccount:
string;
//Mr. T's Mailaccount
cdPort: integer;
//Strato: 465 or 587
cdUseTLS: boolean;
cdSSLConnection: boolean;
//Strato: True
cdTransferEmail:
string;
//Strato: you@youraccout.de
cdUser:
string;
//Strato: you@youraccout.de
cdPass:
string;
//Strato: Strato Password
cdOrganizer:
string;
//Organisator
cdAttendee:
string;
//Empfänger
cdAppointmentStart: TDateTime;
//Anfang Termin
cdAppointmentEnd: TDateTime;
//Ende Termin
cdSummary:
string;
//Betreff
cdLocation:
string;
//Ort
cdBody: TStringList;
//Body
cdDescription:
string;
//Beschreibung
cdPriority: TIdMessagePriority;
//Prioriät
procedure CreateInvitation(Msg_In : TIdMessage);
constructor Create;
destructor Destroy;
override;
end;
var
Form1: TForm1;
cd: TCalendarData;
implementation
{$R *.dfm}
constructor TCalendarData.Create;
begin
inherited;
cdBody := TStringList.Create;
end;
destructor TCalendarData.Destroy;
begin
cdBody.Free;
inherited;
end;
procedure TCalendarData.CreateInvitation(Msg_In : TIdMessage);
var
s: TStrings;
MemoryStream: TMemoryStream;
Attachment: TIdAttachmentMemory;
begin
s :=
nil;
MemoryStream :=
nil;
try
s := TStringList.Create;
MemoryStream := TMemoryStream.Create();
with s
do
begin
Add('
BEGIN:VCALENDAR');
Add('
VERSION:2.0');
Add('
PRODID:-//LeanCredit GmbH//NONSGML AML//DE');
Add('
BEGIN:VEVENT');
Add('
UID:' + cdAttendee);
Add('
DTSTAMP:' + FormatDateTime('
YYYYMMDD"T"HHMMSS"Z"', Now));
Add('
ORGANIZER;CN=' + cdAccount + '
:MAILTO:' + cdOrganizer);
Add('
LOCATION;ENCODING=QUOTED-PRINTABLE:' + cdLocation);
Add('
DESCRIPTION:Test');
Add('
DTSTART:' + FormatDateTime('
YYYYMMDD"T"HHMMSS"Z"', cdAppointmentStart));
Add('
DTEND:' + FormatDateTime('
YYYYMMDD"T"HHMMSS"Z"', cdAppointmentEnd));
Add('
SUMMARY:' + cdSummary);
Add('
END:VEVENT');
Add('
END:VCALENDAR');
end;
s.SaveToStream(MemoryStream);
//Erzeuge den Kalendereintrag
Attachment := TIdAttachmentMemory.Create(Msg_In.MessageParts);
Attachment.ContentType := '
text/calendar';
Attachment.MethodAddress('
request');
Attachment.CharSet := '
utf-8';
Attachment.FileName := '
calendar.ics';
Attachment.LoadFromStream(MemoryStream);
finally
MemoryStream.Free;
s.free;
end;
end;
//TCalendarData.CreateInvitation
procedure SendCalendarRequest(CD: TCalendarData);
var
IdMessage: TIdMessage;
SMTP: TIdSMTP;
SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
IdUserPassProvider: TIdUserPassProvider;
IdSASLCRAMMD5: TIdSASLCRAMMD5;
IdSASLCRAMSHA1: TIdSASLCRAMSHA1;
IdSASLPlain: TIdSASLPlain;
IdSASLLogin: TIdSASLLogin;
IdSASLSKey: TIdSASLSKey;
IdSASLOTP: TIdSASLOTP;
IdSASLAnonymous: TIdSASLAnonymous;
IdSASLExternal: TIdSASLExternal;
begin
IdMessage := TIdMessage.Create(
nil);
try
with IdMessage, cd
do
begin
//Header
ContentType := '
multipart/mixed';
ContentTransferEncoding := '
8 bit';
Encoding := meMIME;
AttachmentEncoding := '
MIME';
Charset := '
utf-8';
//Absender
From.
Name := cdAccount;
From.Address := cdOrganizer;
//Empfänger, Priorität + Nachrichtentext
Recipients.EMailAddresses := cdAttendee;
Priority := cdPriority;
Body.AddStrings(cd.cdBody);
end;
//with IdMessage, md
//Anlage Besprechnungsanfrage erzeugen
cd.CreateInvitation(IdMessage);
SMTP := TIdSMTP.Create(
nil);
try
if cd.cdSSLConnection = true
then
begin
SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(
SMTP);
with SSLHandler
do
begin
MaxLineAction := maException;
SSLOptions.Method := sslvTLSv1;
SSLOptions.Mode := sslmClient;
SSLOptions.VerifyMode := [];
SSLOptions.VerifyDepth := 0;
end;
//with SSLHandler
SMTP.IOHandler := SSLHandler;
if cd.cdUseTLS = true
then
SMTP.UseTLS := utUseImplicitTLS
else
SMTP.UseTLS := utUseExplicitTLS;
end;
if (cd.cdUser <> '
')
or (cd.cdPass <> '
')
then
begin
if cd.cdUseTLS = true
then
SMTP.AuthType := satSASL
else
SMTP.AuthType := satDefault;
IdUserPassProvider := TIdUserPassProvider.Create(
SMTP);
IdUserPassProvider.Username := cd.cdUser;
IdUserPassProvider.Password:= cd.cdPass;
IdSASLCRAMSHA1 := TIdSASLCRAMSHA1.Create(
SMTP);
IdSASLCRAMSHA1.UserPassProvider := IdUserPassProvider;
IdSASLCRAMMD5 := TIdSASLCRAMMD5.Create(
SMTP);
IdSASLCRAMMD5.UserPassProvider := IdUserPassProvider;
IdSASLSKey := TIdSASLSKey.Create(
SMTP);
IdSASLSKey.UserPassProvider := IdUserPassProvider;
IdSASLOTP := TIdSASLOTP.Create(
SMTP);
IdSASLOTP.UserPassProvider := IdUserPassProvider;
IdSASLAnonymous := TIdSASLAnonymous.Create(
SMTP);
IdSASLExternal := TIdSASLExternal.Create(
SMTP);
IdSASLLogin := TIdSASLLogin.Create(
SMTP);
IdSASLLogin.UserPassProvider := IdUserPassProvider;
IdSASLPlain := TIdSASLPlain.Create(
SMTP);
IdSASLPlain.UserPassProvider := IdUserPassProvider;
SMTP.SASLMechanisms.Add.SASL := IdSASLCRAMSHA1;
SMTP.SASLMechanisms.Add.SASL := IdSASLCRAMMD5;
SMTP.SASLMechanisms.Add.SASL := IdSASLSKey;
SMTP.SASLMechanisms.Add.SASL := IdSASLOTP;
SMTP.SASLMechanisms.Add.SASL := IdSASLAnonymous;
SMTP.SASLMechanisms.Add.SASL := IdSASLExternal;
SMTP.SASLMechanisms.Add.SASL := IdSASLLogin;
SMTP.SASLMechanisms.Add.SASL := IdSASLPlain;
end
else
begin
SMTP.AuthType := satNone;
end;
SMTP.Host := cd.cdHost;
SMTP.Port := cd.cdPort;
SMTP.ConnectTimeout := 30000;
SMTP.UseEHLO := True;
SMTP.Connect;
try
SMTP.Send(IdMessage);
finally
SMTP.Disconnect;
end;
//try..finally
finally
SMTP.Free;
end;
//try..finally
finally
IdMessage.Free;
end;
//try..finally
end;
//SendCalendarRequest
procedure TForm1.Button1Click(Sender: TObject);
begin
//Sende Besprechungseinladungen
cd := TCalendarData.Create();
with cd
do
begin
cdHost := '
smtp.strato.de';
cdAccount := '
Auto Calendar';
//Mr. T's Mailaccount
cdPort := 465;
//Strato: 465 or 587
cdUseTLS := true;
cdSSLConnection := true;
//Strato: True
cdTransferEmail := '
noreply@vb-ml.leancredit.de';
//Strato: you@youraccout.de
cdUser := '
User';
//Strato: you@youraccout.de
cdPass := '
Pass';
//Strato: Strato Passwort
cdOrganizer := '
calendar@leancredit.de';
//Organisator
cdAttendee := '
max_mueller@test.de';
//Empfänger
cdAppointmentStart := Now;
//Anfang Termin
cdAppointmentEnd := Now+0.1;
//Ende Termin
cdSummary := '
Besprechung Meier (wwewe)';
//Betreff
cdLocation := '
Buero XY';
//Ort
cdDescription := '
Dies ist ein Text';
//Beschreibung
cdBody.Add('
Dies ist der Body der Mail');
cdPriority := mpNormal;
//Prioriät
end;
SendCalendarRequest(cd);
end;
end.