2010-04-18 3 views

Antwort

4

hier eine Alternative zu RRUZ Vorbild ist:

program SendMailWithCalendarRequest; 
{$APPTYPE CONSOLE} 

uses 
    IdSMTP, 
    Classes, 
    DateUtils, 
    IdMessage, 
    SysUtils; 

procedure SendCalendarRequest; 
var 
    SMTP  : TIdSMTP; 
    MailMessage : TIdMessage; 
begin 
    SMTP:= TIdSMTP.Create(nil); 
    MailMessage := TIdMessage.Create(nil); 
    try 
    SMTP.Host := 'smtp.mailserver.com'; 
    SMTP.Port := 25; 
    SMTP.Username := 'the account'; 
    SMTP.Password := 'the password'; 
    SMTP.AuthType := satDefault; 
    MailMessage.From.Address := '[email protected]'; 
    MailMessage.Recipients.EMailAddresses := 'the Recipient'; 
    MailMessage.Subject := 'Send calendar'; 
    MailMessage.Body.Add('BEGIN:VCALENDAR'); 
    MailMessage.Body.Add('VERSION:1.0'); 
    MailMessage.Body.Add('BEGIN:VEVENT'); 
    MailMessage.Body.Add('ORGANIZER:MAILTO:'+SenderMail); 
    MailMessage.Body.Add('DTStart:'+FormatDateTime('YYYY-DD-DD',Now)); 
    MailMessage.Body.Add('DTEnd:'+FormatDateTime('YYYY-DD-DD', Tomorrow)); 
    MailMessage.Body.Add('Location;ENCODING=QUOTED-PRINTABLE: My home'); 
    MailMessage.Body.Add('UID:'+FormatDateTime('YYYY-DD-DD',Now)+FormatDateTime('YYYY-DD-DD', Tomorrow)); 
    MailMessage.Body.Add('SUMMARY:Appointment Reminder'); 
    MailMessage.Body.Add('DESCRIPTION:Test message'); 
    MailMessage.Body.Add('PRIORITY:5'); 
    MailMessage.Body.Add('END:VEVENT'); 
    MailMessage.Body.Add('END:VCALENDAR'); 
    MailMessage.ContentType := 'text/calendar'; 
    SMTP.Connect; 
    try 
     try 
     SMTP.Send(MailMessage) ; 
     Writeln('OK') 
     except on E:Exception do 
     Writeln(0, 'ERROR: ' + E.Message) ; 
     end; 
    finally 
     SMTP.Disconnect; 
    end; 
    finally 
    SMTP.Free; 
    MailMessage.Free; 
    end; 
end; 

begin 
    try 
    SendCalendarRequest; 
    readln; 
    except 
    on E: Exception do 
     Writeln(E.ClassName, ': ', E.Message); 
    end; 
end. 
+0

Danke, lief ich RRUZ Programm Art in gmail gearbeitet, aber Aussichten, wenn die E-Mail j Abrufen endet. Spezifischer. Der Dienst sendet per Indy automatisch E-Mails vom Server. Jede E-Mail hat einen Text-/Plain-Teil, den Text/HTML-Teil und optional Anhänge. Das funktioniert gut. Beim Versuch, das ical am Ende analog zum Beispiel mit Inhalt Text/Kalender einzubinden; method = Anfrage als letztes Teil friert das Programm nach dem Verschlüsseln der Nachricht für die ersten Teile ein, aber ein Problem im Kalenderteil. Die Nachricht Teil als ob ein Text/Ebene mit den Tstrings der ical und der Inhalt wie erwähnt. –

+0

Dann füllen Sie die TIdMessage wahrscheinlich nicht korrekt aus, bitte zeigen Sie Ihren tatsächlichen Code an. –

+0

mein Code unten, hinzugefügt Teil ist der letzte nach Anlagen ect Prozedur Emailer.BuildCalendar (Msg_In: TIdMessage); var s: TStrings; const TAB = # 9; beginne versuche s: = TStringList.Create; s.Add ('BEGIN: VCALENDAR'); ... andere Zeilen hier hinzugefügt ..... s.Add ('END: VCALENDAR'); // Erstellen Sie die Kalenderteile mit TIdText.Create (Msg_In.MessageParts, s) do beginne ContentType: = 'Text/Kalender; method = "REQUEST"; charset = "UTF-8"; ParentPart: = 0; // IdText.CharSet Ende; endlich am freien; Ende; Ende; .... mit Dank –

4

@ David, die E-Mail-Client als Kalenderanforderung die Anlage erkennt, wenn Sie die Eigenschaft auf ContentType:='text/calendar' einstellen, erfahren Sie auf diesen Link für die iCalendar format Specification

diesen Beispielcode sehen (en Delphi 2010 getestet)

program SendMailWithCalendarRequest; 
{$APPTYPE CONSOLE} 


uses 
    IdSMTP, 
    Classes, 
    DateUtils, 
    IdAttachmentFile, 
    IdMessage, 
    SysUtils; 

procedure SendCalendarRequest; 
var 
    SMTP  : TIdSMTP; 
    MailMessage : TIdMessage; 
    Calendar : TStrings; 
    CalendarFile: String; 
    Attachment : TIdAttachmentFile; 
    SenderMail : String; 
begin 
    SenderMail:='[email protected]'; 
    CalendarFile:=ExtractFilePath(ParamStr(0))+'\appmnt.vcs'; 
    Calendar:=TStringList.Create; 
    try 
     Calendar.Add('BEGIN:VCALENDAR'); 
     Calendar.Add('VERSION:1.0'); 
     Calendar.Add('BEGIN:VEVENT'); 
     Calendar.Add('ORGANIZER:MAILTO:'+SenderMail); 
     Calendar.Add('DTStart:'+FormatDateTime('YYYY-DD-DD',Now)); 
     Calendar.Add('DTEnd:'+FormatDateTime('YYYY-DD-DD', Tomorrow)); 
     Calendar.Add('Location;ENCODING=QUOTED-PRINTABLE: My home'); 
     Calendar.Add('UID:'+FormatDateTime('YYYY-DD-DD',Now)+FormatDateTime('YYYY-DD-DD',Tomorrow)); 
     Calendar.Add('SUMMARY:Appointment Reminder'); 
     Calendar.Add('DESCRIPTION:Test message'); 
     Calendar.Add('PRIORITY:5'); 
     Calendar.Add('END:VEVENT'); 
     Calendar.Add('END:VCALENDAR'); 
     Calendar.SaveToFile(CalendarFile); 
    finally 
    Calendar.Free; 
    end; 

    SMTP:= TIdSMTP.Create(nil); 
    MailMessage := TIdMessage.Create(nil); 
    try 
    SMTP.Host := 'smtp.mailserver.com'; 
    SMTP.Port := 25; 
    SMTP.Username:='the account'; 
    SMTP.Password:='the password'; 
    SMTP.AuthType:=satDefault; 
    MailMessage.From.Address := SenderMail; 
    MailMessage.Recipients.EMailAddresses := 'the Recipient'; 
    MailMessage.Subject := 'Send calendar'; 
    MailMessage.Body.Text := ''; 
    Attachment:=TIdAttachmentFile.Create(MailMessage.MessageParts, CalendarFile) ; 
    Attachment.ContentType:='text/calendar';//set the content type to text/calendar 
    try 
     try 
     SMTP.Connect; 
     SMTP.Send(MailMessage) ; 
     Writeln('OK') 
     except on E:Exception do 
     Writeln(0, 'ERROR: ' + E.Message) ; 
     end; 
    finally 
     if SMTP.Connected then SMTP.Disconnect; 
    end; 
    finally 
    SMTP.Free; 
    MailMessage.Free; 
    end; 

end; 

begin 
    try 
    SendCalendarRequest; 
    readln; 
    except 
    on E: Exception do 
     Writeln(E.ClassName, ': ', E.Message); 
    end; 
end.