C# SMTP Mail Error 5.5.1 Only In Debugger - c#

I'm getting the following error when trying to send an email from my C# application, but only when I'm running it in the Visual Studio IDE
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
If I build my application and install it I do not get this error. I've read through a bunch of similar questions and I've checked all the obvious things, but no existing answer addresses this.
System.Net.Mail SmtpClient and MailMessage
.NET Framework 4.5
Host: smtp.gmail.com
Port: 587
EnableSsl: true
UseDefaultCredentials: false
I know my email credentials are accurate, it's the same ones I use once the application is installed. Something about it trying to send an email from the debugger throws an authentication error.
I'm also pretty sure this used to work. I don't know when it started to fail, and I was too lazy to look into it at the time, but it's growing more and more frustrating. Perhaps I took an update to either Windows or VS that caused it, I don't know.
UPDATE
I wanted to clarify since I've done some more testing. This problem also seems to be related specifically to the app in question. In order to do some testing I created a simple test app that used my same library for email reporting and it works fine in debugger. I have even copied the actual methods from my application into my test app and they work. So there must be something in the app settings that is causing this, but I can't figure it out.

I have resolved this and I wanted to share my experience with the world in case this helps anyone else. I don't know the actual cause of these errors, but I was able to resolve it by poking around and tweaking the project settings of the application. At first I thought perhaps I had conflicting GUIDs that were causing a spam filter to go off, so I starting going through the project settings of the app. While I was there I realized that I didn't actually have a GUID configured for this application and much of the publisher details were all the defaults. I copied the GUID from my ISTool project I use for building it to an installer and I filled out the other important details in the project settings. This caused my settings file to get re-created, so I had to re-configure my app settings, but once that was done email worked. I don't know if this was a safety mechanism to prevent email spamming from hastily thrown together projects or maybe it was blackballed for not having a GUID. Whatever the reason, it seems that accurately filling out the project info makes a difference.
Hope this helps someone else someday :)

Related

HttpListener "Connection Closed" in Browser when using SSL

We have some custom http webservice build on HttpListener in .net 4.8.
This thing works fine on different customer systems, however on one of our new customers system, we have trouble getting SSL to work.
The problem is, that accessing a simple echo page (that just dumps the request into the output), modern browsers like firefox, chrome and edge get a connection reset, once the listener starts writing into the output stream.
Internet Explorer and WebRequests work without any issues.
Im pulling my hair out, all I could find is recommendations to reinstall IIS since this seems to be a known problem in old ASP.net Solutions. However we do not use IIS.
The next problem is, the customers IT is really restrictive and does not allow us to install tools like WireShark or Fiddler.
I dont know if there is any other possible combination of netsh commands to add the ssslcert, im certain by now that i treid everything.
We even used one of our own certificates, but no success.
EDIT It seems to be related to the fact, that the customer is using a Windows Server 2022.
Turns out this is a known problem in Server 2022
https://borncity.com/win/2022/10/22/fix-des-ssl-tls-verbindungsproblems-stand-der-sonderupdates-und-betroffene-anwendungen-21-10-2022/
Disabling TLS 1.3 via registry did the trick for us, as a workaround.

Xamarin Forms - How to use HttpListener with HTTPS in 2022?

I have been working on this for a day or so and have come across quite a few posts and snippets which shed some light on how to run an HTTPS server using HTTPListener in Xamarin Forms, but everything I have come across is very outdated, or targets the wrong platform, (in most cases, Windows). I am targeting Android only at the moment, though would like to do the logic for the server in the shared code, as I will eventually deploy the app to iOS as well.
My main problem has been tracking down a comprehensive guide, or even a list of the steps required. For example, on the HTTPLIstener documentation page (https://learn.microsoft.com/en-us/dotnet/api/system.net.httplistener?view=net-6.0) the text mentions needing to select a Server Certificate for the listener, or it will fail. It then goes on to describe configuring the Server Certificate using Windows-specific tools which do not have an implementation in Xamarin.
I have encountered another post which mentions putting the certificate and private key in question into a specific folder, named after the port number the listener inhabits, i.e. 55555.cer and 55555.pvk. I have tried this, using a self-signed certificate generated using the BouncyCastle library, and it will not work. The HTTP version of the server works perfectly, but the HTTPS side generates an error like:
SSL_ERROR_RX_RECORD_TOO_LONG
This is the same error I was receiving before doing anything other than adding an HTTPS prefix to the listener, so it indicates to me that nothing has changed or been affected by placing the certificate in the correct location.
Finally, I have encountered information which leads me to believe that I need to also add the self-signed certificate to the Android Trusted Certificate store, before I will be able to use it in my application. I'm about to start implementing that, but wanted to check here to see if anyone has any insight to offer that will help me along the way.
So my question is: What are the actual steps required to make HTTPListener with HTTPS support on Xamarin Forms Android work?
It's seemingly been done in the past, so presumably it will still be possible today. I'd really like to use HTTPListener versus a lower level connection API due to the convenience offered.

Run c# code on client side or make a web session interactive?

I'm making an application on c# for signing PDFs. Its works perfectly on my visual studio web project, but when I publish it on my test server it throws me this Error
In this case I'm trying to execute the code that sign a pdf on the server and the error occurs specifically on the line:
System.Security.Cryptography.Pkcs.SignedCms.ComputeSignature()
It is supposed to throws a window on your desktop asking for your certificate (reading a smart Card) and then asking for your PIN just like this
Windows Security Window but I have the hunch that it's not possible because Its implies that the server have to have the possibility to interact with the client's desktop
Ok, now that I've explained all the enviroment that I'm facing, here are the solutions I've tried until now:
1) Trying to correct the Server Error above: I went in the server to IIS>application Pool>MyPage>Advanced Settings>Process Model>Load User Profile and selected True instead of False (Didn't Work)
2) Still trying to correct the Server Error I Went to Computer Management>Services and Application>Services and turned on the service "Interactive Service Detection" (Still not working and doesn't work even if I do the same on the client computer)
3)Finally, I guess that it's not possible to run the code on the server because the Error line above is a native calling of Windows Security so I thought: what if I try to run the code right from the client?. Like a c# applet equivalent or something, well... there are two ways for do that: ActiveX (old technology) and Silverlight (newer). The thing is that I just can't make a simple Silverlight program start on chrome, it does on firefox and IE but if doesn't work on chrome is a totally waste so my last option is to make it run with an ActiveX, and there is almost none useful information in the internet about that
If someone can tell me what to do, either to correct the error or to make my program run from the client side, I would be so grateful
You can't call the system's api from a Web client as this would break the sandbox. If you must use that system call, create a wrapper on the server that will handle the popup, although this would be a very "hacky" solution. You should really be asking why I am trying to use a Web client interface if I must use said native system call.

DNS error when trying to connect to Windows Azure Service Bus

The remote name could not be resolved:
'x.servicebus.windows.net'.TrackingId:bbfe86f8-b5d3
Doing an nslookup works fine.
I can hit the url from the browser with no issues.
Usually rebooting resolves the issue. It seems to be the consistent thing, but sometimes even this doesn't work. Sometimes simply waiting until later fixes the issue.
I've tried closing IIS express, resetting my ip, closing visual studio, etc., but nothing immediately resolves it, other than rebooting, but like I said this doesn't always work, so not sure it's even related.
I've tried disabling my firewall. I uninstalled norton anti-virus, but no luck. I've also disabled Windows Defender.
This only seems to be happen on my Windows 8.1 machine. Even when I'm
experiencing the error, I can run the same code from my Windows 7
machine with no problems. I don't use my Windows 7 machine enough
though to know if it is really a Windows 8 specific issue.
Microsoft mentions possibly using Shared Access Signatures as an alternative for connecting to the service bus, but I'm not looking to rewrite my code over what appears to be a possible bug in Microsoft's SDK. Does anyone know how to diagnose this? I am wondering if there are trace logs that can be setup in web.config specifically for the servicebus perhaps that might give me some additional error information. Or if someone else has run into this and can provide some insight.
This does not seem anything specific to the Service Bus APIs, you can get more information on the IP configuration and reset it on you Windows 8.1 box as follows:
Open an administrator command prompt and type the following:
netsh int ip reset
netsh winsock reset
Check if any errors are listed? If not, go ahead and reboot the computer.
This ended up being a server issue on Microsoft's end which is why it was impossible to resolve through code and machine changes. It took awhile for them to get it figured out and resolved. If anyone has a similar issue they may want want to consider this possibility as well and get in touch with Microsoft.

DotNetOpenAuth OnLoggedIn event never fired

I am a fresher to use the DotNetOpenAuth. And I have download the latest version V3.4.6 from your website which includes samples.
But when I try to test the “OpenIdRelyingPartyWebForms” project, it seems that the “OnLoggedIn=OpenIdLogin1_LoggedIn” event never been fired, so the friendly user name can never be displayed. And I also test the “OpenIdRelyingPartyMvc” project, after I logged in with Yahoo opened, it always give the following information “This message has already been processed. This could indicate a replay attack in progress.” It seems that I can always get this error message.
Further information: I test it in my company then got the above information; but when I go back home, I can successfully use all the DotNetOpenAuth examples and even my own codes with it can work well.
My computer OS in company is: Windows 7
My computer OS in home is: Windows Vista
Maybe the company network environment is different from the network environment at home??? Or maybe it is caused by different OS???
I have seen others to raise a similiar question which is also about "OnLoggedIn" event can not fire, but seems no one reply it.
Can you give any help about this?
Thanks.
I have resolved my problems. I finally found out that it is due to the configuration issue. I just add maxAuthenticationTime="0:10" in the openid section, that is:
"openid maxAuthenticationTime="0:10"",
then I can get the examples run normally. Maybe the default maxAuthenticationTime is less than 10? Maybe in some network environment, it needs more authentication time.
Anyway, thanks for your reply and your excellent work for openid.
It could very well be that your company network has a firewall that blocks something that OpenID needs if your site is on the internal network. Impossible to say what for sure though, being on the outside.
The OS version shouldn't have anything to do with it, however.

Categories

Resources