使用代码将附件添加到Outlook日历邀请 [英] Add Attachment to an outlook calender invite using code

查看:329
本文介绍了使用代码将附件添加到Outlook日历邀请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


  我可以使用c#代码创建和发送Outlook邀请。我现在想要
为会议邀请添加附件并使用代码发送而不会丢失当前结构作为Outlook邀请电子邮件。请帮我解决。


<请注意,我的会议请求就像普通的Outlook邀请,而不是电子邮件的附件。


解决方案1我尝试过:当我使用下面的注释代码添加附件时,我丢失了outlook邀请格式并获得邀请,就像我带有附件的电子邮件一样。

 附件附件=新附件("我的文件位置在这里");  
msg.Attachments.Add(附件);


解决方案2我试过:没有帮助我获得附件和邀请但不会破坏邀请

字符串filepath =" C:\\RamCharan \\\ \\Projects \\temp\\ Invitation_MeetingID_GOES_HERE.mht" ;; 
str.AppendLine(string.Format(") ; ATTACH; FMTTYPE =消息/ RFC822:{0}",文件路径));



  
公开
字符串 BookMeeting()
{
SmtpClient sc = new SmtpClient();
sc.Host = " smtp ip address goes here>" ;

MailMessage msg = new MailMessage();
msg.From = new MailAddress(" emailid到此处" name goes here" ; );

msg.To.Add("发件人电子邮件地址到达此处");


Guid meetingID = Guid.NewGuid();

msg.Subject = "创建会议ID" + meetingID + < span style ="color:#a31515">" at" + DateTime.Now.ToString();
msg.Body = "请在收到我的电子邮件时通知我。这是Body Content。 " ;
msg.BodyEncoding = System.Text.Encoding.UTF8;

StringBuilder str = new StringBuilder ();

str.AppendLine(" BEGIN:VCALENDAR" );
str.AppendLine(" PRODID: - // Ahmed Abu Dagga Blog" );
str.AppendLine(" VERSION:2.0" ; );
str.AppendLine(" METHOD:REQUEST" );
str.AppendLine(" BEGIN:VEVENT" );
str.AppendLine( string .Format(" DTSTART:{0:yyyyMMddTHHmmssZ}" ,DateTime.Now)); // startTime
str.AppendLine( string .Format(" DTSTAMP:{0:yyyyMMddTHHmmssZ}" ,DateTime.UtcNow));
str.AppendLine( string 。格式(" DTEND:{0:yyyyMMddTHHmmssZ}" ,DateTime.Now.AddMinutes(31))); // endTime
str.AppendLine(" LOCATION:方法1位置再次是ram desk");
str。 AppendLine( string .Format(" UID:{0}" ,meetingID));
str.AppendLine( string .Format(" DESCRIPTION:{0}" , msg.Body));
str.AppendLine( string .Format(" X-ALT-DESC ; FMTTYPE = text / html:{0}" ,msg.Body));
str.AppendLine( string .Format(" SUMMARY:{0}" ,msg.Subject));
str.AppendLine( string .Format(" ORGANIZER:MAILTO:{0}" , msg.From.Address));

for int i = 0 ;我< msg.To.Count; i ++)
{
str.AppendLine( string .Format(" ATTENDEE; ROLE = REQ-PARTICIPANT; CN = \" {0} \" ;; RSVP = TRUE:mailto:{1}" ,msg.To [i] .DisplayName,msg.To [i]。地址));
// str.AppendLine(string.Format(" ATTENDEE; CN = \" {0} \" ;; RSVP = TRUE: mailto:{1}",msg.To [1] .DisplayName,msg.To [1] .Address));
}

//添加管理器以发送电子邮件
msg.To.Add( new MailAddress(msg.From.Address,msg .From.DisplayName));
str.AppendLine( string .Format(" ATTENDEE; PARTSTAT = ACCEPTED; CN = \" {0} \":mailto:{1}"
msg.To [msg.To.Count - 1] .DisplayName,msg.To [msg.To.Count - 1] .Address));

//在下面添加此附件会破坏邀请
//附件附件=新附件("我的档案位置在这里");
// msg.Attachments。添加(附件);

//下面没有帮助我获得附件以及邀请但不会破坏邀请
字符串文件路径=" C:\\ \\\RamCharan \\Projects \\ temp \\ Invitation_MeetingID_GOES_HERE.mht" ;;
//str.AppendLine(string.Format("ATTACH;FMTTYPE=message/rfc822:{0} ",文件路径));


str.AppendLine(" BEGIN:VALARM" );
str .AppendLine (" TRIGGER:-PT15M" );
str.AppendLine(" ACTION:DISPLAY" );
str.AppendLine(" DESCRIPTION:Reminder" );
str.AppendLine(" END:VALARM" );
str.AppendLine(" END:VEVENT" );
str.AppendLine(" END:VCALENDAR" );
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(" text / calendar" );
ct.Parameters.Add(< span style ="color:#a31515">" method" ," REQUEST" );
AlternateView avCal = AlternateView.CreateAlternateViewFromString (str.ToString(),ct);
msg .AlternateViews.Add(avCal);

sc.Send(msg);

return "会议ID为" + meetingID + " :成功创建于" + DateTime.Now.ToString();
}

解决方案

< blockquote>

您是否可以使用嵌入式附件?请参阅派生自AttachmentBase的类LinkedResource。


Hi All,

   I am able to create and send outlook invite using c# code. i now want to add an attachment to the meeting invite and send using code without losing the current structure as outlook invitation email.Please help me how.

Note my meeting request goes like an normal outlook invite and not like an attachment to an email.

Solution 1 i tried :When i add an attachment using the commented code below i lost the outlook invitation format and get the invitation like an email with the attachment which i have given.

Attachment attachment = new Attachment("my file location goes here");
msg.Attachments.Add(attachment);

Solution 2 i tried : doesnt help me get the attachment along with invite but doesn't spoil the invite

 string filepath ="C:\\RamCharan\\Projects\\temp\\Invitation_MeetingID_GOES_HERE.mht";
str.AppendLine(string.Format("ATTACH;FMTTYPE=message/rfc822:{0}",filepath));




public
string BookMeeting()
{
SmtpClient sc = new SmtpClient();
sc.Host = "<smtp ip address goes here>";


MailMessage msg = new MailMessage();
msg.From = new MailAddress("emailid goes here", "name goes here");

msg.To.Add("sender email address goes here");

Guid meetingID = Guid.NewGuid();

msg.Subject = "Create Meeting ID" + meetingID + "at " + DateTime.Now.ToString();
msg.Body = "Please let me know when you get my emails.Here is the Body Content . ";
msg.BodyEncoding = System.Text.Encoding.UTF8 ;

StringBuilder str = new StringBuilder();

str.AppendLine("BEGIN:VCALENDAR");
str.AppendLine("PRODID:-//Ahmed Abu Dagga Blog");
str.AppendLine("VERSION:2.0");
str.AppendLine("METHOD:REQUEST");
str.AppendLine("BEGIN:VEVENT");
str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", DateTime.Now)); //startTime
str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddMinutes(31)));//endTime
str.AppendLine("LOCATION: Method 1 location is ram desk again");
str.AppendLine(string.Format("UID:{0}", meetingID));
str.AppendLine(string.Format("DESCRIPTION:{0}", msg.Body));
str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", msg.Body));
str.AppendLine(string.Format("SUMMARY:{0}", msg.Subject));
str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", msg.From.Address));

for (int i = 0; i < msg.To.Count; i++)
{
str.AppendLine(string.Format("ATTENDEE;ROLE=REQ-PARTICIPANT;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[i].DisplayName, msg.To[i].Address));
//str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[1].DisplayName, msg.To[1].Address));
}

//Adding organizer to send email
msg.To.Add(new MailAddress(msg.From.Address, msg.From.DisplayName));
str.AppendLine(string.Format("ATTENDEE;PARTSTAT=ACCEPTED;CN=\"{0}\":mailto:{1}",
msg.To[msg.To.Count - 1].DisplayName, msg.To[msg.To.Count - 1].Address));

//Adding this attachment below is spoiling the invite
//Attachment attachment = new Attachment("my file location goes here");
//msg.Attachments.Add(attachment);

//below doesnt help me get the attachment along with invite but doesn't spoil the invite
// string filepath ="C:\\RamCharan\\Projects\\temp\\Invitation_MeetingID_GOES_HERE.mht";
//str.AppendLine(string.Format("ATTACH;FMTTYPE=message/rfc822:{0}",filepath));



str.AppendLine("BEGIN:VALARM");
str.AppendLine("TRIGGER:-PT15M");
str.AppendLine("ACTION:DISPLAY");
str.AppendLine("DESCRIPTION:Reminder");
str.AppendLine("END:VALARM");
str.AppendLine("END:VEVENT");
str.AppendLine("END:VCALENDAR");
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
msg.AlternateViews.Add(avCal);

sc.Send(msg);

return "Meeting id is " + meetingID + " : Created Sucessfully at " + DateTime.Now.ToString();
}

解决方案

Will you be OK with embedded attachment instead? See class LinkedResource that derives from AttachmentBase.


这篇关于使用代码将附件添加到Outlook日历邀请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆