2010-04-18 227 views

回答

4

这里是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 := '[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

谢谢,我检索电子邮件Ĵ当跑RRUZ程序那种在Gmail中工作,但前景ust终止。 更具体。该服务使用Indy从服务器发送电子邮件,每个电子邮件都有一个文本/纯文本部分,文本/ html部分和可选附件。这工作正常。当试图结合类似于内容文本/日历的例子时, method = request作为最后一部分,程序在对第一部分的消息进行编码后冻结,但在日历部分出现问题。 消息部分就像一个文本/平原,其中包含所提及的内容和内容的tstrings。 – 2010-04-19 11:24:58

+0

然后你可能没有正确填写TIdMessage,请显示你的实际代码。 – 2010-04-19 21:42:27

+0

我的代码如下,添加的部分是最后的附件等 程序Emailer.BuildCalendar(Msg_In:TIdMessage); var s:TStrings; const TAB =#9; begin try s:= TStringList.Create; s.Add('BEGIN:VCALENDAR'); ...在这里添加的其他行..... s.Add('END:VCALENDAR'); //使用TIdText.Create(Msg_In.MessageParts,s)创建日历部分 do begin ContentType:='text/calendar;方法= “REQUEST”;字符集= “UTF-8”'; ParentPart:= 0; // IdText.CharSet end; 终于s.free;结束; 结束; ....谢谢你 – 2010-04-20 09:57:35

4

@大卫,如果将该属性设置为ContentType:='text/calendar'电子邮件客户端将识别为一个日历请求的附件,看到这个链接,iCalendar format Specification

看到此示例代码(测试连接德尔福2010年)

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. 
相关问题