|
With this code I keep receiving the error message saying :
"
The request failed. The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. "
Does anyone have any ideas on how I can get my C# program to send emails via EWS in my Exchange environment?
Thanks
using System.Net;
using System.Net.Mail;
using Microsoft.Exchange.WebServices;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
private void emailNotifyUser ()
{
Microsoft.Exchange.WebServices.Data.ExchangeService service = new Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2010_SP1);
service.Credentials =
new Microsoft.Exchange.WebServices.Data.WebCredentials("you@you.com", "password1", "domain.com);
service.TraceEnabled = true;
service.TraceFlags = Microsoft.Exchange.WebServices.Data.TraceFlags.All;
service.Url = new Uri("HTTPS:
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate);
Microsoft.Exchange.WebServices.Data.EmailMessage email = new Microsoft.Exchange.WebServices.Data.EmailMessage(service);
email.ToRecipients.Add(To);
email.Subject = "HelloWorld";
email.Body = new Microsoft.Exchange.WebServices.Data.MessageBody("First email using EWS Managed API");
email.Body.BodyType = Microsoft.Exchange.WebServices.Data.BodyType.HTML;
email.Send();
}
private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors policyErrors)
{
bool result = false;
if (cert.Subject.ToUpper().Contains("cas-server-name"))
{
result = true;
}
return result;
}
|
|
|
|
|
Does the code work if you just return true from the ValidateRemoteCertificate method no matter what?
|
|
|
|
|
I will try that tomorrow. Is it as simple as just setting it to true?
|
|
|
|
|
I have no idea. This is just a test to narrow down the problem.
|
|
|
|
|
It does not work, I received the following error
An element node 'soap:Envelope' of the type Element was expected, but node 'Autodiscover' of type Element was found.
|
|
|
|
|
I double checked my autodiscover url with the following code and then matching that fixed it
Get-WebServicesVirtualDirectory |fl identity,internalurl,externalurl
Thanks for helping me to get that error and point me in the right direction!
|
|
|
|
|
Hi, all.
I developed an application over the last few years on a laptop with screen resolution 1600x900 and a desktop at 1920x1200. All was good. I then got a 4K monitor for my desktop, and started editing the app there. All looked good. When I went back to my laptop to do more development, the main form, when VS2015 loads the solution, gets shortened (Size.Y is smaller than it should be). I can lengthen it manually, and save. Now when I go back to the desktop all looks good still, so I do more coding, and save it. When I go back to my laptop, it's shortened again. I could do a hack to correct it at run-time, forcing the Size.Y to be the right value, but that's not nice, and doesn't fix the fact that I need to resize it in order to see the rest of the form in the VS IDE.
It's not a show-stopper, but it's very annoying! I appreciate any input anyone can offer.
Thanks.
Len
|
|
|
|
|
Have you considered getting the current Screen dimensions from the 'Screen object, and then setting the 'MinimumSize and/or 'MaximumSize properties of the Form ... in addition to (possibly) setting the current size of the Form ?
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Thanks for the suggestion. I tried that, and even the MinimumSize.Y value changes in the same way as the Size.Y does. It seems like it has something to do with the scaling difference, but other controls on the form scale correctly - just the form length changes. Bizarre!
|
|
|
|
|
Hi,
What you describe resembles some of my earlier experiences with WinForms , although what follows actually applies to both dimensions; I would guess the horizontal effect is present but less noticeable due to the somewhat different aspect ratio of your monitors.
I am assuming your laptop and desktop use different resolutions, probably 100% (=96dpi) for the laptop and 125% (=120dpi) or more for the 4K desktop monitor. WinForms normally does some automatic scaling when you switch resolutions. It gets controlled mainly through the AutoScaleMode property of each Form you use.
Possible values are:
Inherit , which probably is fine for forms/Dialogs with a parent, not for the main Form; I never used it.
None , it disables all scaling attempts and leaves it all up to your code (not so easy to get something acceptable);
Font , the default, mostly fine if your app is text oriented;
Dpi , may well be the preferred one if your app is image oriented.
You're out of luck when both text and images are important to you!
What I typically end up doing when it is sufficiently important, is:
- use AutoScale.Dpi on every Form (the easiest is to inherit from a FormBase or a DialogBase that sets a number of things you want (or you want to experiment with) for all your forms;
- use the Anchor property to stretch 2D containers such as ListBox, TextBox, SplitContainer...;
- most often stretch the main Form (which has StartPosition: Manual) with constructor code similar to:
<br />
InitializeComponent();<br />
Rectangle wa=SystemInformation.WorkingArea;<br />
Width=wa.Width-20;<br />
Height=wa.Height-20;<br /> or something more sophisticated if you need to support multimonitor setups, or your app remembers its Location and Size on the local machine (registry, Properties, whatever).
BTW1: I don't use SplitContainer, it seems to have anchoring bugs; I use my own.
BTW2: I dislike UserControls, they have some quirky behavior too.
BTW3: And I don't use PictureBoxes, they are pretty useless, but their scaling might be correct, I couldn't tell...
Hope this helps.
|
|
|
|
|
Whenever I come to (by writing code from example to see if it works) "Console.Writeline..." I want to enter all information by text into a textbox (or textblock, Windows Phone 8) without the use of console.
|
|
|
|
|
I may be listening in Gibberish, but your question is rather unclear. Could you describe it in the form of a use-case?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Never mind, I found what I wanted, elsewhere. It is "String.Format("{0} blah, blah {1}") to write to a textbox (instead of using Console.WriteLine.
|
|
|
|
|
What you need to do is you need to re-write your Console application to Windows Phone application. If I understand your problem, it is more like this (forgive the difference, but I am keeping it to ensure that the concept is clear)
Console.WriteLine("Enter your age: ");
int age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Your are is {age}.");
Now, this can be re-written in Windows Phone application like this,
int age = Convert.ToInt32(ageTextBox.Text);
ageLabel.Text = $"Your are is {age}.";
This way, the above code can be changed to be used in Windows Phone, which worked similarly in a Console application project. Of course, you cannot replace Console with other objects, you have to write their names in the code to get the controls as objects. I would recommend that you learn more on MSDN: How to create your first app for Windows Phone 8[^]
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Upvoted; just knew I was listening wrong
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for your reply, but I found the answer to my problem, elsewhere. It is "String.Format("{0} blahblah {1} years of age") and fill it in a textbox, instead of Console.WriteLine, that goes to Command Prompt.
|
|
|
|
|
That code just creates a templated string, fills it with the parameters being passed. That has nothing to do with writing to consoles, or writing to textboxes. It is just the way of building strings.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I am not familiar with WinPhone C# programming, however, there is a general strategy I've often used to deal with a similar issue:
1. set a global flag that will determine where output goes: to Console, or TextBox
private const bool OutputToConsole = true; // true for debugging
2. in your code:
private void SomeMethod(string blah)
{
if(OutputToConsole)
{
Console.WriteLine("my blah is:" + blah);
}
else
{
someTextBox.Text = String.Format("my blah is: {0}", blah);
}
} This gets tiresome, but you can make this a bit easier to write by pre-defining template strings to use, and wrapping the whole thing up in an Extension Method for Type String:
public static class StringExtensions
{
public static bool OutputToConsole = false;
private static StringBuilder sb = new StringBuilder();
public static void WriteString(this string content, bool toconsole, TextBox tbxtarget = null, string template = "")
{
sb.Clear();
sb.Append((template == "")
? content
: String.Format(template, content));
if (OutputToConsole || toconsole || tbxtarget == null)
{
Console.WriteLine(sb.ToString());
}
else
{
tbxtarget.Text = sb.ToString();
}
}
} So, now, if I have two TextBoxes on some Form, 'textBox1, and 'textBox2, and a Button, 'button1, I can:
public const string template0 = "blah state is: {0}";
private void button1_Click(object sender, EventArgs e)
{
"medium blah".WriteString(true, template: template0);
"empty blah".WriteString(false, textBox2, template0);
} The first call to 'WriteString writes "blah state is: medium blah" to the Console, the second writes "blah state is: empty blah" to 'textBox2.
Note: I assume Windows Phone programming supports Extension Methods; if that's not the case, let me know.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Your WriteString extension method isn't thread-safe.
Also, there's not a lot of point using a StringBuilder if you're only going to append a single string.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
As always, thanks for the feedback, Richard.
If you care to say a few words about why it's not thread safe, I'd be grateful; I have virtually no experience dealing with multi-threaded apps, or multi-user apps.
Yes, the use of 'StringBuilder here is a bit over-kill, but the example you see here is extracted/altered from code I used where a lot more is logged, and there is a great deal more done with strings.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
It's not thread-safe because you're sharing a single StringBuilder object, without synchronizing access to the shared state.
Imagine two threads calling WriteString at the same time. You could end up with:
T1: Clear
T2: Clear
T1: Append "Message from T1"
T2: Append "Message from T2"
T1: Output "Message from T1Message from T2"
T2: Output "Message from T1Message from T2"
Or:
T1: Clear
T1: Append "Message from T1"
T2: Clear
T2: Append "Message from T2"
T1: Output "Message from T2"
T2: Output "Message from T2"
Or:
T1: Clear
T1: Append "Message from T1"
T2: Clear
T1: Output ""
T2: Append "Message from T2"
T2: Output "Message from T2"
Or any other sequence of calls which could result in incorrect output.
Also, the StringBuilder class isn't thread-safe, so you could end up corrupting the internal state of the object and getting weird output or exceptions.
And that's before you consider the possibility that the JIT compiler is free to reorder operations if doing so doesn't change the outcome of the code on a single thread:
C# - The C# Memory Model in Theory and Practice[^]
C# - The C# Memory Model in Theory and Practice, Part 2[^]
If you really needed to use a static instance of the StringBuilder class, you'd either need to add a lock block around the access, reducing the performance of your code; or you'd need to use Thread Local Storage[^] to have a single instance of the class per thread.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Enlightening ! thanks, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
By default the GridView inplace editor has the mouse wheel handler which allows to change the data inside by scrolling the mouse wheel
Could you please suggest how to cancel the mentioned mouse wheel handler
|
|
|
|
|
You already asked this question in QA. Don't repeat the same question in multiple forums. It just hampers efforts to get a colaborated answer.
|
|
|
|
|
Hello,
I am using 'FileSystemWatcher.enableraiseevents' to get the events when a directory, or file in a directory changes. I have used FileSystemWatcher.Error to catch the errors. These are the errors logged in my system.
Exception : System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out, Hash code: 28048521, Type: System.IO.ErrorEventArgs, To string: System.IO.ErrorEventArgs
Exception : System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully, Hash code: 1658455, Type: System.IO.ErrorEventArgs, To string: System.IO.ErrorEventArgs
Exception : System.ComponentModel.Win32Exception (0x80004005): Unknown error (0x490062), Hash code: 27762102, Type: System.IO.ErrorEventArgs, To string: System.IO.ErrorEventArgs
My question is what is the meaning of these errors ?
Why I am getting these errors ?
Please help me.
|
|
|
|
|