EWS - Attachment Not Sent With Invitation - exchangewebservices

I am facing an issue with sending attachments with invitation using EWS Managed API. Appointments attendees are not receiving any attachments added to the appointment but
attachment do appears in the calendar of the person that created the appointment.
Here is my code snippet:
try
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
service.Credentials = new WebCredentials("calendar_user", "password1", "acme");
service.Url = new Uri("https://acme.com/EWS/Exchange.asmx");
Appointment appointment = new Appointment(service);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "tin.tin#acme.com");
String UID = "D09F3FF6-1461-414C-89E8-C05BC3B66A4A";
appointment.ICalUid = UID;
appointment.Subject = "Test Subject";
appointment.Body = "Test Content.";
appointment.Start = new DateTime(2012, 07, 11, 17, 00, 0);
appointment.End = appointment.Start.AddMinutes(30);
FileAttachment attachment = appointment.Attachments.AddFileAttachment(#"C:\Users\tintin\Documents\Test.xlsx");
attachment.IsInline = false;
appointment.RequiredAttendees.Add("tin.tin#acme.com");
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
}
catch (Exception ex)
{
}

Look like EWS has horrible limitation with attachment handling. I found a workaround to resolve this issue which requires updating appointment object twice.
appointment.ICalUid = UID;
appointment.Subject = "Test Subject";
appointment.Body = "Test Content.";
appointment.Start = new DateTime(2012, 07, 11, 17, 00, 0);
appointment.End = appointment.Start.AddMinutes(30);
FileAttachment attachment = appointment.Attachments.AddFileAttachment(#"C:\Users\tintin\Documents\Test.xlsx");
attachment.IsInline = false;
appointment.Save(folderCalendar, SendInvitationsMode.SendToNone);
appointment.RequiredAttendees.Add("tin.tin#acme.com");
appointment.Update(ConflictResolutionMode.AutoResolve, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);

Looks like this issue is specific to Exchange Server 2010 Service Pack 1. I got similar issue and when I changed the version to SP2 issue got resolved. Below code solved the problem
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

A second update did the trick, but it will cause a cancelled meeting at the bottom. Can't use it in product.
It doesn't work to change the version to SP2.
Still find a better solution.

Yes, EWS has some issue, while updating the meeting with new attachments it is not getting updated for the first time. Needed 2 instances to update it.
Microsoft.Exchange.WebServices.Data.Appointment meet1 = await
Microsoft.Exchange.WebServices.Data.Appointment.Bind(service, strMessageID);
meet1.Attachments.Clear();
foreach (FileUpload Item in
objCreateEvent.strAttachmentUploadPath)
{
meet1.Attachments.AddFileAttachment(Item.fileName,
Item.filePath);
}
meet1.RequiredAttendees.Clear();
foreach (string ToItem in objToIds)
{
meet1.RequiredAttendees.Add(ToItem);
}
await
meet1.Update(ConflictResolutionMode.AlwaysOverwrite,
SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);
Microsoft.Exchange.WebServices.Data.Appointment
meeting2 = await Microsoft.Exchange.WebServices.Data.Appointment.Bind(service,
strMessageID);
meeting2.Attachments.Clear();
foreach (FileUpload Item in
objCreateEvent.strAttachmentUploadPath)
{
meeting2.Attachments.AddFileAttachment(Item.fileName, Item.filePath);
}
meeting2.RequiredAttendees.Clear();
foreach (string ToItem in objToIds)
{
meeting2.RequiredAttendees.Add(ToItem);
}
await
meeting2.Update(ConflictResolutionMode.AlwaysOverwrite,
SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);

Related

StmpClient use works for remote users via VPN but not for users in office, on the network

I've implemented the .NET SmtpClient to send emails programmatically. Multiple users of the application and at various stages, an email is automatically sent. For users that are running the application from home, over VPN, the email almost always works. For users at the office, the email fails, "Failure sending mail" is exception message with no inner exception. The email server is MS Exchange, for large financial institution. Not using SSL, using port 25.
SmtpClient mailClient = new SmtpClient (getSmtpServer(), getSmtpPort());
mailClient.Timeout = 20000;
mailClient.UseDefaultCredentials = true;
MailAddress from = new MailAddress ( getSmtpFromAcct(),
"My Application",
System.Text.Encoding.UTF8);
MailAddress to = new MailAddress ( toEmail );
MailMessage message = new MailMessage(from, to);
for( int i = 1; i < toUsers.Count; i++)
{
BeanUser beanUser = toUsers[ i ];
message.To.Add( beanUser.getEmail() );
}
message.Subject = subject;
message.Body = messageBody;
mailClient.Send(message);

How to get a Flag property from email message?

Can I somehow get a Flag property from EmailMessage or Item object? There is no getFlag() method, I also didn't find it in item.getPropertyBag(). I'm using ews-java-api-2.0. flag setting on outlook web app
There is a strongly type flag property in EWS in 2013 and greater so you could modify the EWS Java source to cater for that. Otherwise if you use the underlying Extended properties you can get the same information eg
ExtendedPropertyDefinition PR_FLAG_STATUS = new ExtendedPropertyDefinition(0x1090, MapiPropertyType.Integer);
ExtendedPropertyDefinition FlagRequest = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, 0x8530, MapiPropertyType.String);
PropertySet fiFindItemPropset = new PropertySet(BasePropertySet.FirstClassProperties);
fiFindItemPropset.Add(FlagRequest);
fiFindItemPropset.Add(PR_FLAG_STATUS);
FolderId FolderToAccess = new FolderId(WellKnownFolderName.Inbox, MailboxToAccess);
ItemView ivItemView = new ItemView(1000);
ivItemView.PropertySet = fiFindItemPropset;
FindItemsResults<Item> FindItemResults = null;
do
{
FindItemResults = service.FindItems(FolderToAccess, ivItemView);
foreach (Item itItem in FindItemResults.Items)
{
Console.WriteLine(itItem.Subject);
Object FlagValue = null;
if (itItem.TryGetProperty(FlagRequest, out FlagValue))
{
Console.WriteLine("Flag : " + FlagValue);
}
Object PR_FLAG_STATUS_Value = null;
if (itItem.TryGetProperty(PR_FLAG_STATUS, out PR_FLAG_STATUS_Value))
{
Console.WriteLine("PR_FLAG_STATUS : " + PR_FLAG_STATUS_Value);
}
}
ivItemView.Offset += FindItemResults.Items.Count;
} while (FindItemResults.MoreAvailable);
Theres a full list of flag properties https://msdn.microsoft.com/en-us/library/ee201258(v=exchg.80).aspx

The request failed with HTTP status 401: Unauthorized. SSRS

I have a class in a MVC web project that processes SSRS.
When I run the app in the IIS machine I access the reports OK.
When run from another machine on the network gives me "The request failed with HTTP status 401: Unauthorized."
The Report Server has own unique credentiais. Does not accept the logon credentials on the network
Annex a part of the class
reportViewer.ProcessingMode = ProcessingMode.Remote;
reportViewer.ServerReport.ReportServerUrl = new Uri(System.Configuration.ConfigurationManager.AppSettings["RSUrl"]);
reportViewer.PromptAreaCollapsed = true;
reportViewer.ShowParameterPrompts = false;
reportViewer.SizeToReportContent = true;
reportViewer.InteractivityPostBackMode = InteractivityPostBackMode.AlwaysAsynchronous;
reportViewer.AsyncRendering = false;
if (reportType == "GRP")
{
reportViewer.ShowToolBar = false;
reportViewer.ShowPageNavigationControls = false;
}
else //if (reportType == "RPT")
{
reportViewer.ShowToolBar = true;
reportViewer.ShowPageNavigationControls = true;
}
strReportName = _reqObjNm;
strReportPath = System.Configuration.ConfigurationManager.AppSettings["RSPath"];
reportViewer.ServerReport.ReportPath = strReportPath + strReportName;
string RSUsername = System.Configuration.ConfigurationManager.AppSettings["RSUserName"];
string RSPwd = System.Configuration.ConfigurationManager.AppSettings["RSPwd"];
string RSDomain = System.Configuration.ConfigurationManager.AppSettings["RSDomainFull"];
//App_Start.ReportViewerCredentials rvCreds = new App_Start.ReportViewerCredentials(RSUsername, RSPwd, RSDomain);
//reportViewer.ServerReport.ReportServerCredentials = rvCreds;
reportViewer.Visible = true;
if (reportViewer.ServerReport.GetParameters().Count > 0) // HERE breaks :(
If I understand your question correctly I think you need to add a "ReportUser" to the remote SSRS server as a local user and in SSRS manager grant the local "ReportUser" user account proper access.

Updated Appointment via EWS shows UTC instead of local TZ

I have researched for this issue and am unable to find a solution.
The SO post TimeZone change to UTC while updating the Appointment referred to the same problem, but I've tested the solution and its not working.
Here is what's wrong:
Does anyone have a solution? The time is correctly reflected on Outlook, Emails etc. It's just that the text shown is misleading to people and causing confusion.
*Note that the code below can be copied and pasted into a console app for testing.
var timezone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
var service = new ExchangeService(ExchangeVersion.Exchange2013, timezone);
service.Credentials = new NetworkCredential("myemail#mydomain.com", "mypassword");
service.Url = new Uri("https://outlook.office365.com/Ews/Exchange.asmx");
var meeting1 = new Appointment(service);
meeting1.Subject = "Test Meeting";
meeting1.Body = "Test body";
meeting1.Start = new DateTime(2013, 8, 22, 9, 0, 0); //my default time is GMT+8
meeting1.End = meeting1.Start.AddHours(2);
meeting1.Location = "Conf Room";
meeting1.RequiredAttendees.Add("someone#outlook.com");
meeting1.Save(SendInvitationsMode.SendToAllAndSaveCopy);
Console.WriteLine("1st invite sent");
var id = meeting1.Id.ToString();
System.Threading.Thread.Sleep(5000); //break for a while...
//re-fetch the appointment
var meeting2 = Appointment.Bind(service, new ItemId(id),
new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Start,
AppointmentSchema.End, AppointmentSchema.StartTimeZone,
AppointmentSchema.EndTimeZone, AppointmentSchema.TimeZone));
Console.WriteLine( meeting2.StartTimeZone ); //shows Tokyo Standard Time correctly.
meeting2.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
meeting2.EndTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
meeting2.Start = new DateTime(2013,8,23, 9,0,0, DateTimeKind.Unspecified);
meeting2.End = meeting2.Start.AddHours(2);
meeting2.Subject = "Updated Test Meeting";
meeting2.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);
meeting2.Load(new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Start,
AppointmentSchema.End, AppointmentSchema.StartTimeZone,
AppointmentSchema.EndTimeZone, AppointmentSchema.TimeZone,
AppointmentSchema.Body, AppointmentSchema.NormalizedBody,AppointmentSchema.TextBody));
Console.WriteLine( meeting2.StartTimeZone ); //shows Tokyo Standard Time correctly.
I've been having the same issue as we're using ExchangeVersion.Exchange2010_SP2 but i'm managed to get round this using:
appointment.Save(SendInvitationsMode.SendToNone);
// to fix the issue of updating appointment sets timezone to UTC, we use ExchangeVersion.Exchange2007_SP1
service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = false;
service.Credentials = new WebCredentials(Account, Password);
service.Url = new Uri(url);
service.Timeout = 600000;

subscription in reporting services

I want to subscribe report on specific schedule in reporting services 2008. i.e report will dilever to user automatically on schedule. I am using visual studio 2008. I have done the configuration setting (rsreportserver.config, app.config after adding refrences of asmx files) by refrence msdn. The code is running fine (no exception occur) and I also get subscription id through calling create subscription indicate all going fine. But after running the code no entry made in Subscription table of ReportServer database. And also not get any mail. While through report server web tool, I can get email and also entery made in database but not from coe. Please someone help me. What I am missing. Plz help
Code is given follow: (Keep in mind, I am using VS2008)
void SendReportEmail()
{
RSServiceReference.ReportingService2005SoapClient rs=new RSServiceReference.ReportingService2005SoapClient();
rs.ClientCredentials.Windows.AllowedImpersonationLevel = new System.Security.Principal.TokenImpersonationLevel();
string batchID = string.Empty;
RSServiceReference.ServerInfoHeader infoHeader = rs.CreateBatch(out batchID);
BatchHeader bh = new BatchHeader()
{
BatchID = batchID,
AnyAttr = infoHeader.AnyAttr
};
string report = "/PCMSR6Reports/PaymentRequestStatusMIS";
string desc = "Send email from code to Hisham#comsoft.com";
string eventType = "TimedSubscription";
string scheduleXml="<ScheduleDefinition xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><StartDateTime xmlns=\"http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices\">2010-03-06T15:15:00.000+05:00</StartDateTime></ScheduleDefinition>";
RSServiceReference.ParameterValue[] extensionParams = new RSServiceReference.ParameterValue[7];
extensionParams[0] = new RSServiceReference.ParameterValue();
extensionParams[0].Name = "TO";
extensionParams[0].Value = "Hisham#comsoft.com";
extensionParams[1] = new RSServiceReference.ParameterValue();
extensionParams[1].Name = "IncludeReport";
extensionParams[1].Value = "True";
extensionParams[2] = new RSServiceReference.ParameterValue();
extensionParams[2].Name = "RenderFormat";
extensionParams[2].Value = "MHTML";
extensionParams[3] = new RSServiceReference.ParameterValue();
extensionParams[3].Name = "Subject";
extensionParams[3].Value = "#ReportName was executed at #ExecutionTime";
extensionParams[4] = new RSServiceReference.ParameterValue();
extensionParams[4].Name = "Comment";
extensionParams[4].Value = "Here is your test report for testing purpose";
extensionParams[5] = new RSServiceReference.ParameterValue();
extensionParams[5].Name = "IncludeLink";
extensionParams[5].Value = "True";
extensionParams[6] = new RSServiceReference.ParameterValue();
extensionParams[6].Name = "Priority";
extensionParams[6].Value = "NORMAL";
RSServiceReference.ParameterValue[] parameters = new RSServiceReference.ParameterValue[10];
parameters[0] = new RSServiceReference.ParameterValue();
parameters[0].Name = "BranchId";
parameters[0].Value = "1";
parameters[1] = new RSServiceReference.ParameterValue();
parameters[1].Name = "UserName";
parameters[1].Value = "admin";
parameters[2] = new RSServiceReference.ParameterValue();
parameters[2].Name = "SupplierId";
parameters[2].Value = "0";
string matchData = scheduleXml;
RSServiceReference.ExtensionSettings extSettings = new RSServiceReference.ExtensionSettings();
extSettings.ParameterValues = extensionParams;
extSettings.Extension = "Report Server Email";
try
{
string sub="";
RSServiceReference.ServerInfoHeader SubID = rs.CreateSubscription(bh, report, extSettings, desc, eventType, matchData, parameters, out sub);
rs.FireEvent(bh, "TimedSubscription", sub);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
Detail response will be highly appricated.
Try adding # at the beginning of your xml string #"