delphi - 如何发送带有日历请求的电子邮件(内容类型 : text/calendar)

标签 delphi indy10

我尝试将icalendar代码嵌入到通过indy发送的内容类型为文本/日历的电子邮件中,但当我添加为附件时,它只是卡在电子邮件的编码上,它只是作为附件到达并且确实不像其他日历请求那样提示。有没有人有如何通过 indy 执行日历请求的示例代码?

最佳答案

以下是 RRUZ 示例的替代方案:

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 := 'mail@server.com'; 
     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. 

关于delphi - 如何发送带有日历请求的电子邮件(内容类型 : text/calendar),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2661469/

相关文章:

delphi - 创建 Windows 服务来打开程序 - Delphi

delphi - DCEF3 - Delphi Chromium Embedded - Javascript 和应用程序代码之间的通信

delphi - Indy tcp 服务器 - 确定服务器的 IP 和端口

delphi - 升级 Indy 库以使用最新的 OpenSSL 库

c++ - 指向Delphi中指针的指针

delphi - 用 Delphi 实现 LDAP 服务器

delphi - Delphi 7 和 Delphi XE4 中的默认日期格式

delphi - DataSnap 将入站请求限制为 16k

c++ - 如何使用 TIdHTTPProxyServer 重定向 Post 请求

Delphi Indy HTTPS Web 服务器错误(观察到违反协议(protocol)的 EOF)