ASP.NET not sending emails to my own domain - c#

I have two servers one linux server running cpanel/whm which act as a mail server and DNS Server for my domain and I host the website for the same domain on a different windows web server.
I have set up windows server with SMTP service to be able to send emails from my ASP.NET application.
Everything is going OK and my application sends emails correctly everywhere except to my own domain itself. If I sent and email to an email address like this somename#mydomain.com it is never delivered although sending emails using the same application to any domain succeeds.
Could you help me what should be the reason for this problem?
Regards,
Ehab Zaky

This is most likely caused by a setting on your SMTP Server itself.
Most smtp servers by default will not accept traffic if it claims to be from a local domain but is not a valid local user. So the first thing I would try is send the email from something that is a real working email address configured on your SMTP server. If that works, then you know what the problem is and can choose your course of action from there.
If that doesn;t work, then I would check the security settings of your SMTP server and look for limitations / restrictions regarding local domains. I am not a Linux user, but this seems to me to be whats probably happening.
Dave

Related

Configure IIS to receive email

According to this answer it is possible to configure IIS to receive email. That is what I would like to do. But the answer says it's done under IIS SMTP under domains.
I connected to my website (on a web host) using IIS Manager and the only SMTP option I see is SMTP E-mail under the ASP.NET heading. (I have one more heading which is IIS, but doesn't have any SMTP under it.)
Clicking on SMTP E-mail shows me an option to "Use this feature...when sending e-mail...". and it has a textbox for E-mail address and radio buttons to choose from Deliver e-mail to SMTP server and Store e-mail in pickup directory.
I don't see any option for allowing it to receive emails.
So where is the option to receive emails?
(If you have a different way to receive emails without any action taken on them, I'd be glad to hear about it. I want to process the email regardless of the address it's being sent to as long as it's to my domain.)
You need the IIS 6 manager for that - even if you have IIS 7-8-9-10 installed. The SMTP part is still only in IIS 6 :(
It's not problem to run them side-by-side and you will use IIS 6 manager only for SMTP
With this option you could send and receive emails.
The IIS 6 manager looks like this:
And with you Windows system you need to install the SMTP server:
which give you IIS 6 (SMTP only)
See also https://www.interserver.net/tips/kb/how-to-setup-and-configure-smtp-server-on-windows-server-2008-r2/
And http://www.vsysad.com/2017/05/install-and-configure-smtp-server-on-windows-server-2016/
and see also How to configure SMTP in IIS 7?
I have a scenario where I wanted my web application to accept inbound emails and process them. I didn't find the SMTP server that comes with IIS to be helpful.
What ended up being a much better solution for receiving mail messages for me was to use an inbound email parsing service. You configure a domain's MX record to point to their (parsing service provider) mail server and their mail server parses the message and Posts to a page on your web server. My ASP.Net MVC Controller Action looks like this:
public ActionResult InboundMessage(FormCollection collection, HttpPostedFileBase attachment1, string attachments, string to, string from)
They get the email and call my code. I don't have to worry about any of the SMTP details. I've been using this for several years and it's worked great for me.
I'm not sure how recommending a specific product goes over around here, but if you Google "inbound email parser", you'll find several options.
If you want to go the original route, it is possible to receive inbound mail. It will write incoming messages to the "Drop" folder. (If you Google "IIS SMTP Drop folder", you will find information about how to do this.)
Before I found the Inbound Parse service, I ended up cobbling my own mail server together from some code on found on GitHub, but even then, parsing the parts of a message was a much bigger undertaking than I was expecting.

Will PickupDeliveryLocation work when using an outgoing mail server on a different domain than our own?

What happens when the outgoing mail server is not part of the local domain? For example, I work for company xyz.com and our smtp server is mail.xyz.com. We host client sites in a multitennant application. We allow our users to point to their own smtp server using email configurations we store in our database.
The code we use to send emails loads the configuration with the smtp information and the authorization needed to send an email on behalf of our clients through their email system.
Currently we are running into concurrency issue that is causing timeouts for various clients when notifications are being processed. They are currently configured to be sent immediately. I've read that moving to the local pickup directory can solve this issue.
I am concerned if I specify a path like C:\Temp\Mail but use an SMTP connection to a clients mail server is that going to work? Doesn't the email being created and sent from the pickup location need to be on the same domain as the smtp server?
How will the clients SMTP server know .eml file has been generated for their domain and needs to be sent out without having to change our client's environment? If someone can provide any information as to how the SMTP and Specified Pickup Locations work I would greatly appreciate it.
The basic operation of an SMTP server in this sense is to monitor a specific set of folders and perform an action when an event occurs. Where your concern is is in that a file dropped into the pickup location is parsed and sent.
The basic SMTP operation allows any email server to send any email regardless of the domain that the email says it is from. This obviously caused issues with fraudulent emails and has been mitigated originally by Designated Sender and further extended via SPF, DIM, and DMARC.
So what your client would need to do is to have their SMTP setup properly and configured for your email domain(s). On your end it would be recommended to only allow the Designated Senders generate emails, and set up SPF etc for those clients as well
Microsoft has a good article on the SMTP basics How SMTP Works
Google has plenty of lists for SPF, DKIM, and DMARC as well.

How can I redirect mail from my server to a relay mail server? (AZURE)

EDITED :
I am quite new in this and I found out that when you send an email to patrick#fish.com the mail is sent to the ip address of fish.com and whatever server is hosted there should do the work of redirecting or processing the mail.
I have a web role (website) on azure which holds the content of myweb.com .
The thing is, I do not know how to configure the re-direction on that server. I know you could add an MX record on the server but azure does not give me that option since in azure there is a load balancer exposing the public ip and we have no access to it.
I do have a mail relay service which I hired to redirect the email but I dont know where to configure the re direction on azure.
Maybe there is a way to configure this in web.config inside the visual studio solution?
Don't use direct SMTP. You will have much better results with a service like SendGrid.
Microsoft has a special deal for free SendGrid service (<= 25,000 per month) for Windows Azure customers, so there's no reason not to use it.
http://www.windowsazure.com/en-us/develop/net/how-to-guides/sendgrid-email-service/
Redirection and MX records don't have anything to do with Azure - you setup MX records to handle your mail where ever your DNS is hosted.
In order to redirect a mail with webrole on Azure you either
have to configure DNS so that the mailserver is located somewhere
outside of Azure, or
receive the incoming mail and send it further to
a new recipient.
The first approach has nothing to do with Azure.
The second approach is not possible, for even though you can send a mail from your service by using SendGrid, as it was pointed out by Matt Johnsohn, there is no possibility to host an SMTP server in your webrole. Webrole itself is hosted within IIS and the latter provides its own bindings for SMTP, FTP and some other protocols. You can host a WCF service within your webrole instance that would use net.tcp binding for connection -- but you will not be able to bind the port 25 required for standard SMTP connection.

Testing the availability of an smtp mail server using c#

I have an MVC3 web application written in C#. I am using McvMailer to send emails from within the application, which is all working fine.
The issue i have is that our smtp server is not anywhere near the web server that will be hosting the application, and that it is possible that on occasion the smtp server may not be available.
I need to be able to detect whether or not the smtp server is available before giving a user the option to send emails. Thus far the best i have come up with is to ping the smtp server using the solution from #John Leidegren answer in this post.
However, it appears that the router is responding to the ping and not the smtp server. Baring in mind that the main cause for the server not being available would be the internet connection failing, i could probably live with this solution if i had to, but it would be nice if i could ensure the availability of the smtp service prior to attempting to send emails.
Any ideas?
Yes, ping is a good start, but to determine if the SMTP gateway is available, issue the HELO command through the SMTP port.
I'll try to find a good example.
Edit:
You're in luck. Here's a complete TELNET client written in C#. https://www.nuget.org/packages/Telnet

Sending an email in C#

Is it possible to send an email in C# console, without needing and SMTP server?
Edit:
Why do I need another SMTP server? Can not I use my localhost machine as a server..?
Edit:
I just need to send an email from with my domain name, for example abc#mydomain.com
Is that possible? what do I need to do this in my C# program... I do not care about receiving emails, I just care about sending them....
Thanks
You don't have to depend on a local SMTP server if you don't have one. However, you will have to connect to a SMTP server anyway. Here is why.
You must achieve the following steps:
Determine what is the mail exchange servers of a given domain.
Connect to that mail exchange server and deliver your mail.
Those steps are normally done by your local SMTP server. Another advantage of your local SMTP server is that it will handle its queue and continue to try to deliver your email if it fail.
How to determine the MX records of a give domain.
I suggest you to have a look at this answer. Basically, you have to do a query on a DNS server to get the list of MX records of the domain name of the email address you want to send an email to.
How to connect to a mail exchange server
Well the answer will disappoint you. Exactly like you connect to your local SMTP server. Using the TcpClient, you connect to one of the mail exchange server you got at the previous step on port 25 and start the delivering process using the SMTP protocol.
The trick here is that you must handle multiple MX servers. They are usually listed with a preference. If the first one is unreachable, you try the next one and so on...
That is something your SMTP server can handle for you too.
If you really want to build that logic yourself, please have a look at the DirectSend method of the SmtpClient class of this open source project I'm involved in.
As #TomTom points out, the entire mail infrastructure depends on SMTP. What you can do is to skip the output (relaying) SMTP server and send the message directly to the receiving SMTP server.
To do that you need to create some kind of queuing mechanism (there is no guarantee that the receiving SMTP server can serve you when you try to connect) and that you can look it up.
MX records are entries stored in DNS servers and are used to find SMTP servers. You can find a article here with a MX lookup example: http://www.codeproject.com/KB/IP/dnslookupdotnet.aspx
However, I DO recommend that you install a local SMTP server and let it take care of the above mentioned issues.
Yes, Basically figure out where to sent the email and send it. i.e. a DNS MX lookup for the domain to find out the SMTP server.
Every email needs an SMTP server on the receiving side.
You can use gmail or yahoo SMTP server, if you don't want to install your own.
Before sending mail you first need to authenticate, otherwise sending mail is not going to possible.
You need access to some kind of email server to send your email, and your email will most likely pass through one or more SMTP servers on it's way to the recipient. However, the email server you connect to might let you send the email without using SMTP. For example, Exchange might let you use MAPI or CDO to send emails. Though I think that CDO is not officially supported by .Net and simple MAPI is deprecated in Windows and should not be used. You might be able to use Exchange Web Services as described here: Introducing the Exchange Web Services Managed API 1.0
If you have another email server than Microsoft Exchange, that server might have some kind of API you can use.
Something I do often is to create gmail account and send through that account.
You just need your SmtpClient to connect to the host smtp.gmail.com on port 587 with the username, password, and enableSSL property set to true.

Categories