On my website i send e-mails. My situation is these mails are being sent when using my local development machine, and not on my production environment.
The web.config is the same on both sites:
<system.net>
<mailSettings>
<smtp from="info#domain.dk" deliveryMethod="Network">
<network host="mail.domain.dk" userName="info#domain.dk" password="mypassword" port="26"></network>
</smtp>
</mailSettings>
</system.net>
In my code, I send it like this:
SmtpClient client = new SmtpClient();
client.Send(mail);
I have no idea how to debug this problem, as it is the exactly same code on both production and development.
Any ideas on how to start debugging / solving the problem?
EDIT:
I managed to get a log from the server. Error is:
2012-11-01 20:41:58,383 [11] FATAL GKBusiness.Managers.MailManager [(null)] - Email exception: Mailbox unavailable. The server response was: Access denied - Invalid HELO name (See RFC2821 4.1.1.1)
Hmm
My situation is these mails are being sent when using my local development machine, and not on my production environment.
<network host=..... port="26">
If you are in a shared hosting environment, it's likely that ASP.Net is set to Medium Trust - and if so, SMTP is restricted to port 25.
It will work in your local environment because ASP.Net is set to Full Trust (in local/VS dev).
Related
It was working fine when tested on the local SMTP but when deployed over the Amazon web server getting the following exception.
The SMTP server requires a secure connection or the client was not authenticated.The server response was: Authentication required
After going through so many blogs and posts it seems I should complete two steps to make it work.
enableSsl="true" in webconfig
second to install certificate on the app in IIS, we didn't buy the certificate so for testing I do the same as per the Scott Gu
Enabling SSL on IIS 7.0
My web config entry is as below
<smtp deliveryMethod="Network" from="behindthecurtain#empowher.com">
<network host="email-smtp.us-east-1.amazonaws.com" userName="xxxx" password="xxxx" port="587"
defaultCredentials="false" enableSsl="true"/>
</smtp>
So what else we can do to make it working ? guys any idea I'm totally stuck as you guess.
Problem:
I am trying to connect to a remote mailserver to send emails from an ASP.NET MVC 4 app. Despite using the details that my client has given me to setup the web.config, I am getting the following error:
No connection could be made because the target machine actively refused it 127.0.0.1:25
Setup:
I have an ASP.NET MVC 4 website that needs to send emails. The mailserver is NOT installed on the same box as the webserver.
There is no smtp client or server installed on the webserver. Is this needed?
The client has little experience with hosting their own webserver. I have always connected to mail servers using the hosting companies instructions. This company does not seem to have anyone with the expertise. I am an external consultant, with no experience in networks or mailservers.
Web.Config:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="systems#medreport.co.uk">
<network host="MYHOST1" userName="MyUser" password="PASSWORD" clientDomain="myhost1.mydomain.co.uk" />
</smtp>
</mailSettings>
</system.net>
My reasoning:
From the error, it seems that the ASP.NET MVC app is looking for a mailserver on the localhost machine, ie, the same machine as the webserver. It isn't there, so I get the error.
If that is correct, then there must be something wrong with the attributes of the tag in my web.config. These attributes are not pointing at a valid server, so I am presuming that the system is defaulting to a mailserver on localhost. Is this reasoning correct?
Questions:
I may not have been given the correct name for the host or for the clientDomain attributes of the <network> tag. As a result, the mvc app tries to find a mailserver on localhost. Is this reasoning correct?
I have been given a clientDomain name of the type clientDomain="myhost1.mydomain.co.uk". However, I am trying to connect not over the internet, but over the client's intranet. Should I not have a clientDomain attribute that reflects that I am connecting over an intranet?
The website uses SSL. I have tried using the enableSsl attribute to no avail. However, I presume that the enableSsl attribute relates to communication with the mailserver, not the webserver. Is this correct? As the mail server is on their internal network, they aren't, I understand, using SSL for the mailserver.
An alternative theory would be that there is a firewall issue that is bouncing me out of the mailserver box. But surely I would get a more specific error if that were the case...?
EDIT:
Do I need to install SMTPclient on the webserver for it to be able to connect to the mailserver on a different box?
OK, I have solved this problem: I had the following code in my mail sending routine:
SmtpClient client = new SmtpClient("localhost");
client.Send(message);
Note the hardcoded "localhost".
The only problem is that now it gives me the following error:
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for abc#xyz.efg
But that, as the Jungle Book would say, is another story.
This is the error I get
No connection could be made because the target machine actively
refused it 127.0.0.1:25
here is my web.config snippet:
<mailSettings>
<smtp from="local#local.com">
<network host="localhost" port="25"/>
</smtp>
</mailSettings>
I (think) I have setup my smtp server through IIS. I went into the IIS Manager tool set
e-mail address to:local#local.com
SMTP Server: localhost
Port: 25
Authentication Settings : Not required
By doing all of this, am I theoretically setting up my web application to send email from the localhost? not sure why I am getting that error?
Thanks!
In my web.config file I have specified settings for sending mail. In particular I have these settings:
<system.net>
<mailSettings>
<smtp>
<network host="smtp.example.com" port="25" userName="user" password="pass"/>
</smtp>
</mailSettings>
</system.net>
Now the problem is that my isp suddently (without warning of course) have decided to block port 25 meaning I have to change to port 26 in my development envoiremnet. I belive the best way would be to change to port 26 in the IIS manager (this way I do not need to change anything when publishing my webapp to the remote server).
But how do I tell my asp.net webapp to use the default IIS setting?
check port no 587 its also use for smtp because most of ISP and web hoster block port 25 for security reason.
I have code that relies heavily on email notification. In my web.config I am able to specify an smtp server like this:
<system.net>
<mailSettings>
<smtp from="myaccount#mydomain.com">
<network host="mail.mydomain.com" port="25" userName="myusername" password="mypassword" defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>
This is acceptable, but I would like to implement 2 or 3 exchange servers here in the event that (for what ever reason) smtp server 1 goes offline, I need a backup option.
Is there any quick / built in way to achieve this fail safe in .net, or is there a trusted manual way to implement this. My existing send mesage code looks like this (but watered down):
MailMessage message = new MailMessage();
SmtpClient client = new SmtpClient();
client.Send(message);
Notice its pulling the host directly from the configuration.
Any ideas what is best practice here for this scenario?
<network host="localhost" port=...
and configure the local SMTP transport to relay to your rendundant servers.
that way you won't loose emails because of transient network problems (the local MTA will just hold on to them).
There's an SmtpClient constructor that takes a host name and port. You could have a list of servers, try send the mail and if the server is unavailable it will throw an exception which you catch and retry with other server from the list.