Web job throws Smtp exception on Azure website - c#

I've a web job that is trying to send an email when it reads something from the Azure poision q.
public static void ProcessPoisonNotification(
[QueueTrigger("parkingticketnotification-poison")] ParkingTicketNotificationBO notificationBo,
TextWriter log)
{
var message = "xxx xxx xxx xxx xxx => POISON message: " + notificationBo.Dump();
Console.WriteLine(message);
log?.WriteLine(message);
PoisonEmailNotifier.SendFailureMessage(notificationBo);
}
The Email notifier is using code from the main web applicaiton, which can send emails. but the Web job throws the following exception. Is it because the web application is blocking port 25?

The Email notifier is using code from the main web applicaiton, which can send emails. but the Web job throws the following exception.
Base on my experience, as the Web application and WebJob are in the same environment, if it is worked in the Web application, it should be also worked in the Azure WebJob.
If WebJob is worked locally, please have a try to remote debug the WebJob. More details about how to remote debug the webjob, please refer to the tutorials.
Note: Click the Settings tab, and change Configuration to Debug, before it is published.
Besides,we also can use Azure SendGrid to send email easily.

That looks like Windows Socket Error Code 10013. You can find out more about it here.
Microsoft has two suggestions - you likely either have insufficient permissions or another service is bound to the target port. If you know that traffic on port 25 is not open on your host, it seems likely that this is the cause. However, you may instead have some other service listening to that port.

Related

Sending mail via local IIS smtp server from ASP.NET core app silently fails

UPDATE: This turned out to be simple operator error - I failed to read the log file properly, which did indicate successful delivery on the IIS level.
Turns out that mails to this particular test address were blocked silently for unknown reasons unrelated to dotnet or IIS, by Gmail. Very sorry for posting something with such a simple solution and thanks to those that replied with helpful advice.
ORIGINAL QUESTION:
I have a Windows server with IIS SMTP server installed.
I'm trying to send mails from my ASP.NET Core app with this code:
var client = new SmtpClient();
client.Host = "127.0.0.1";
client.Send(mailMessage);
The code doesn't throw an exception, there is nothing in Windows error logs, nothing is logged to SMTP logs. It just fails silently.
The result of the Send() method is just the message itself, no error message or anything else helpful.
I tried in IIS to configure the SMTP Server but doesn't help.
I also tried other options like UseDefaultCredentials and to have it make a file in the Drop folder - in that case it says "not supported."
This exact same code works perfectly fine from my ASP.NET Standard app on the same server.
Thanks in advance! :-)
This turned out to be simple operator error - I failed to read the log file which indicated successful delivery on the IIS level. The mails to this particular test address were blocked silently for unknown reasons by Gmail. Very sorry for posting something with such a simple solution and thanks to those that replied with helpful advice.

Azure - Push Notifications - Failed to send test message

In Azure i have created a sample notification hub and tried to send test Toast notification for windows. And i ended up with below exception in Azure.
Failed to send test message. Error: {"readyState":4,"responseText":"{\"error\":{\"message\":\"Bad Request\",\"code\":\"BadRequest\"}}","responseJSON":{"error":{"message":"Bad Request","code":"BadRequest"}},"status":400,"statusText":"Bad Request"}.
[Find the screenshot for reference]
https://i.stack.imgur.com/6tbFm.png
You need to configure the Windows(WNS) under Notification Settings first. You can follow this document(https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-windows-store-dotnet-get-started-wns-push-notification#configure-wns-settings-for-the-hub)
I have tested it on my side, after following all the steps in the document, it works fine.

How to enable the Push Notification on Enterprise Network

Problem:
Case i) I got an exception while running the below code connected with enterprise network running on virtual machine.
try
{ PushNotificationChannel channel = null;
channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
}
i.e Timeout error while requesting for the Channel URI for push notification.
Case ii) Tried to get the url/server address which might be blocked by the enterprise network while connecting with WNS using fiddler but unfortunately was not successful.
Note: If I use open network the above code works as charm .
Looking for help, to fix the push notification issue on enterprise network. Also, if anyone knows how to get the WNS Server path/url which is being called when we requested for push channel uri.
I have replied this issue in this thread, you should make sure that your enterprise network do not have any policy which may block the following URLs. You can contact your network administrator to check the firewall settings.
1: The URL for Creating Channel URI: notify.windows.com
2: The URL for getting token: https://login.live.com/accesstoken.srf

WCF service:400 bad request when accessing from local machine

I have a WCF Service hosted and the client is hosted on the same server. I try to show some error message via a dialog box. its working as expected when i try to perform some action which throws that error in server but its showing Bad request when i try to work on Local machine.
Can't post the configuration file. Client machine So :) . Hosting is IIS
I found that in the controllers catch block where i am calling the wcf service whenever we are having an exception we are setting
Respose.StatusCode = (int)HttpStatusCode.BadRequest;
return Json(execption.Message);
Does this have anything to do ?
I added this setting in the web config and i am able to see the actual message in my local machine too
<httpErrors existingResponse="PassThrough" />
Is there any other way of doing it from coding part

Azure TopicClient.Send() never sends a message and it hangs

I am attempting to follow a Windows Azure tutorial to send a message to a topic on Microsoft's Azure service bus. I have created the namespace and the topic. I then set up ACS and grabbed my connection string. My connection string allows Manage, Listen, Send. When I execute my code, the Send(message) just hangs. It never times-out nor does it continue. The CPU is not maxed and I can break out of the code and close the program. No message arrives in Azure. When I watch my network traffic in fiddler, it looks to me like it is never finishing the authentication negotiations. I see a post to my namespace .servicebus.windows.net that returns a 201 then a post and a get at an IP address that belongs to Azure service bus with a /$servicebus/webstring/{guid}. Neither of these web request ever get a response back from the server. Here is my code. It stops running on client.Send(message);
static void Main(string[] args)
{
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
string connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
var client = TopicClient.CreateFromConnectionString(connectionString, "clients");
Console.WriteLine(client.IsClosed);
var message = new BrokeredMessage("Test message.") {TimeToLive = TimeSpan.FromMinutes(15)};
client.Send(message);
Console.WriteLine("Done");
Console.ReadKey();
}
Any ideas on how to get this code to post a message to Azure service bus?
I'm also seeing this behavior when using this code and it appears to be linked to the ServiceBusEnvironment.SystemConnectivity.Mode you have set. If you comment that out it goes through. That mode isn't mentioned in the tutorial. The default the mode is Auto and it detects if it can send via TCP first.
With that said, I'd like to suggest you use the following code instead:
string connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
MessagingFactory factory = MessagingFactory.CreateFromConnectionString(connectionString);
MessageSender testQueue = factory.CreateMessageSender("TestTopic");
BrokeredMessage message = new BrokeredMessage("Test message ");
testQueue.Send(message);
One of the benefits of using the MessageSender instead of the TopicClient or QueueClient directly is that your code doesn't care if the destination is a Topic or a Queue. If you later needed to change from one to another your code here wouldn't have to change. Likewise, using a MessageReceiver on the consuming code is better as well.
I dont see that issue, I can post the message on a topic with same code and receive it via a subscription as well. The SAS key I use is generated on Topic itself. My the issue you had was temporary issue?
It appears to be our corporate firewall. It is actively refusing connections on unknown ports (9354) instead of passively. This seems to keep the Microsoft library for Azure from auto-detecting the connection and switching to https. It appears that with an active refusal of the connection at 9354 an exception get thrown in the library instead of trying http. Likewise, if I set the mode to just Http, it hangs, but when I am outside the corporate firewall it does not hang. It would be nice if this library worked with an active refusal on port 9354.

Categories

Resources