简体   繁体   中英

c# exchange web services over tls1.2

I have spent the last few weeks searching the Internet for a solution to this issue without any luck so I am turning to the community here for help.

I am attempting to write a test application in c# that uses Exchange Web Services over TLS1.2 to connect the Exchange Server 2010 and send an email.

I have used the example downloaded from https://code.msdn.microsoft.com/Send-Email-with-Exchange-50189e57 as a starting point with minor changes to suit our Exchange configuration.

Our Exchange server is configured to use TLS 1.2 If I run the program from inside our domain it is successful but if I run it from outside then I get the following message: “The requested security protocol is not supported”

We are using Using dotnet 4.5 and the code below is my test code.

private void sendButton_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            service.Url = new Uri(ExchangeServerURI);
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            service.Credentials = new WebCredentials(MailUserName, MailPassword, "api");

            EmailMessage message = new EmailMessage(service);
            message.Subject = subjectTextbox.Text;
            message.Body = bodyTextbox.Text;
            message.ToRecipients.Add(recipientTextbox.Text);
            message.Save();

            message.SendAndSaveCopy();

            System.Windows.MessageBox.Show("Message sent!");
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

Any help to get this working would be much appreciated,

Thanks,

John

The problem was caused by the server that I was running the program from not having Dotnet 4.5 installed on the. I wrongly made the assumption that it was installed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM