我试图将icalendar代码嵌入到电子邮件中,通过indy通过内容类型文本/日历发送,但它只是挂在编码上当我作为附件添加时,它只是作为附件到达并且不会像其他日历请求那样提示。有没有人得到如何通过indy做日历请求的示例代码?如何发送带有日历请求(内容类型:文本/日历)的电子邮件
5
A
回答
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.
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.
相关问题
- 1. 使用java发送每封电子邮件的日历邀请
- 2. 发送Outlook日历作为电子邮件使用PHP邀请
- 3. 通过电子邮件发送ICS日历文件Vb.net
- 4. 日历和内容类型
- 5. 如何发送添加日历事件(不是邀请)的电子邮件?
- 6. 用java电子邮件发送日历事件
- 7. 谷歌日历API(Python)的send_event_notifications不发送电子邮件
- 8. 如何使电子邮件日历邀请自动接受(PHP)?
- 9. PHP日历 - 如何让它发送新的事件的电子邮件通知?
- 10. 通过Wordpress电子邮件发送Google日历邀请表单提交
- 11. 无法发送谷歌日历事件非Gmail的日历
- 12. Outlook 365 API - 创建日历事件时禁用自动发送电子邮件
- 13. 请求谷歌日历api
- 14. 从应用程序发送的Android电子邮件保存在Gmail日历
- 15. 发送邀请与谷歌日历API
- 16. 发送Outlook日历邀请PHP
- 17. 发送邀请到谷歌日历
- 18. 如何制作Google日历等电子邮件通知程序?
- 19. iPhone:使用自定义内容类型发送电子邮件
- 20. 如何使通过Google日历API创建的活动发送邀请电子邮件?
- 21. 使用内容类型的文本发送JSON请求/ plain
- 22. 在java邮件API中发送日历邀请作为邮件附件
- 23. 发送带有SMTP的电子邮件
- 24. asp.net或winform中的jquery事件日历类型日历
- 25. 如何发送带有参数和内容类型的HttpDelete请求android
- 26. 带日期时间的PHP日历类
- 27. Outlook日历互操作 - 如何获取发件人电子邮件地址?
- 28. 电子邮件未发送内容
- 29. 内容发送到电子邮件
- 30. 日历验证插件没有日历
谢谢,我检索电子邮件Ĵ当跑RRUZ程序那种在Gmail中工作,但前景ust终止。 更具体。该服务使用Indy从服务器发送电子邮件,每个电子邮件都有一个文本/纯文本部分,文本/ html部分和可选附件。这工作正常。当试图结合类似于内容文本/日历的例子时, method = request作为最后一部分,程序在对第一部分的消息进行编码后冻结,但在日历部分出现问题。 消息部分就像一个文本/平原,其中包含所提及的内容和内容的tstrings。 – 2010-04-19 11:24:58
然后你可能没有正确填写TIdMessage,请显示你的实际代码。 – 2010-04-19 21:42:27
我的代码如下,添加的部分是最后的附件等 程序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