Mailbox unavailable error - asp.net

When trying to send out an email in a .NET site, the following error is being encountered:
Mailbox unavailable. The server response was: No such user here
Does this error appear if the code is trying to send to an email address which doesn't exist?
Thanks.
I now have more information about this error. The emails are sent from 'noreply#[domain]'. When the emails are sent to an email address of the same domain, the emails are sent without a problem. This error only appears when the email addresses being sent to are not from the same domain. I don't know if that's any use?

This happens when you specify a domain with your NetworkCredentials. If you specify a domain (third argument) then you can only send to valid mailboxes within that domain. Leave it out to be able to send to any address outside the domain.
var client = new SmtpClient("smtp.server.com");
client.UseDefaultCredentials = false;
// The following will be able to send to anyone outside the domain.
client.Credentials = new NetworkCredential("user", "password");
// The following will only work when sending to users on server.com
client.Credentials = new NetworkCredential("user", "password", "server.com");

Could be that your password is incorrect. I had to reset the password on the mail server, then the error went away.

This may happen when you switch from 2.0 platform to 4.0. As it was explained here you need to tell IIS explicitly that you are not using default credentials and domain. Use the following syntax in web.config:
<network host="mail.younameit.com" port="25"
userName="account#younameit.com" password="youchoose"
defaultCredentials="false" clientDomain=""/>
The last two parameters are most important to fix this problem.

This sounds like an smtp issue
Try setting your smtp server info in the web.config file like this :
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network defaultCredentials="false" host="mail.blah.com" password="xxxx" port="25" userName="ex#blah.com"/>
</smtp>
</mailSettings>
</system.net>
This is a decent article detailing this section of the web.config and how to access it with code behind :
http://dotnetslackers.com/Community/blogs/kaushalparik/archive/2008/09/06/accessing-web-config-file-smtp-mail-settings-programmatically.aspx

This Q/A was useful to me in a similar situation. For us, the key fact was that the error only occurred for email addresses on a different domain. I learned that our new webhost/mail server setup is intentionally configured this way. (A previous one with the same hosting co. was not.) Some combination of app code or Web.config settings might have solved our problem, but the most direct way forward was to create a no-reply account on our domain, so that now no-reply#ourdomain.com IS valid, and IS allowed to send to external addresses.
No modifications to code or the Web.config were needed. The latter calls out only "from" and "host" and the credentials are not needed in our hosting environment. (When we override the nominal "from", we need to override it to be some other address that's valid on our domain.

Related

System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable.

I get this error when trying to send an email using Asp.net application using SMTP on IIS 7.5
The error is "System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: No such user here at System.Net.Mail.SmtpTransport.SendMail(... "
What i have in web.config is
<system.net>
<mailSettings>
<smtp from="support#mysite.com" deliveryMethod="Network">
<network host="hostname" port="25" password="password" userName="you#yoursite.com" />
</smtp>
</mailSettings>
</system.net>
I really don't understand what should be the username and password here. I get the same error when i put defaultcredentials = "true" instead of username and password. Is there something to do with toaddress. The toaddress is myid#mydomain.com, which works for all other emails, etc.
Please advice me where i am doing wrong!! Thank you in advance!
The userName and password settings refer to the credentials for connecting to the SMTP server. Make sure you don't confuse this with the username and password for the from or to address, which is not relevant to the SMTP server.
You may want to try a tool like SMTPDiag to help you figure out any SMTP connectivity issues you have. However, your error seems to indicate that connectivity is fine but that mail cannot be delivered.
Ram if you are using a web host and you have SMTP support in your package... Then check their control panel.
Also as Jacob I want to remind you that FREE SMTP user accounts that web hosts offer are different from credentials to connect to the SMTP server itself. Usually the former is that's free with web hosts and the latter is not included as long as you don't have a dedicated server I think.
If you don't find it in their control panel then call support... They will be able to give you those details if applicable.

GoDaddy Send Email

I am using ASP.Net 4.0 with MVC 3 and C# to try and send an email from my site. This code works on other hosts but for some reason GoDaddy is erroring out. Here is the code I am using.
var fAddress = new MailAddress("customers#email.com");
var tAddress = new MailAddress("mygodaddyaddress#email.com");
var message = new MailMessage(fAddress, tAddress)
{
Subject = subject,
Body = body
};
var client = new SmtpClient("relay-hosting.secureserver.net");
client.Send(message);
Here is the error I am receiving
Mailbox name not allowed. The server response was: sorry, your mail was administratively denied. (#5.7.1)
Any other GoDaddy users here that can shed some light?
It might be something to do with the from address:
Problem seem to be the FROM email address. The FROM email address must be an email address with the hosted domain to avoid this error. For example if you have a hosted domain yourdomain.com, your FROM email address should be something like username#yourdomain.com.
Source:
http://www.cosmocentral.com/2009/01/553-sorry-your-mail-was-administratively-denied/
It could be because neither email address is native to the mail server used by GoDaddy, and thus you'd need to allow relaying. This is just one possibility, I think the best approach would be to contact them directly.
Your From address does not need to be a GoDaddy email. It is the user/password for the domain that must be valid. This is what the Web.config should have:
<system.net>
<mailSettings>
<smtp from="me#test.com">
<network host="smtpout.secureserver.net" port="80" userName="foo#bar.com" password="yourpassword" defaultCredentials="false" />
</smtp>
</mailSettings>
</system.net>
Then you can initialize it in code-behind with this:
var mailclient = new SmtpClient();

Unable to send to all recipients localhost asp.net

Trying to send email via ASP.NET (classic ASP on the server works fine) and getting the "Unable to send to all recipients." error. Mail server is setup on localhost, Windows 2003 server 64-bit.
Web Config is as follows:
<mailSettings>
<smtp from="rob.hudson#ttu.edu">
<network host="127.0.0.1" port="25" defaultCredentials="true" />
</smtp>
</mailSettings>
Code that generates:
MailMessage mm = new MailMessage();
mm.From = new MailAddress("rob.hudson#ttu.edu");
mm.To.Add(email);
mm.Bcc.Add("rob#iteachwriting.com");
mm.CC.Add("susan.lang#ttu.edu");
mm.Subject = "Your ENGL" + course + "-" + section+ " RaiderWriter account";
mm.Body = sb.ToString();
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Send(mm);
If you have more than one invalid/non-existent email address in your recipients, this error message might happen on some email server, and on our email server the case applies for those email addresses are no longer valid because the employees left the company. Please let me know if you find any other possible cause.
Check if the sending mailbox is full - over the allocated quota.
that can be if:
1)the user or pass are wrong
2)not enable SSL
3)less secure app is not enable
4)you have not log in in server with this mail
In our case the reason was that the SMTP-Server refused messages sent by a machine with a specific IP-Address.
SMTP-Server was part of IIS and there was a list of IPs configured which were allowed to use this SMTP-Server. The client machine in question was not part of the list so we got "Unable to send to all recipients." (or "Senden an alle Empfänger nicht möglich." in german).
Sending from a "valid" client worked.
The error message from the SMTP-Server in this case was pretty misleading.
i struggle a lot and found that there were issue with my Application Pool. I set defaultAPPPool and my code worked.

can an asp.net page send an email to the user

My aspx page is hosted by Discountasp.net. I can use System.Net.Mail.MailMessage to send an email but it seems it must be TO my Discountasp.net acct. (They let you set email accts for your site.)
I want a form that does a calc and sends the info directly to the user who has typed in their email addr.
Here is a link to the DiscountASP.NET "How to send email in ASP.NET 2.0" FAQ: https://support.discountasp.net/KB/a364/how-to-send-email-in-aspnet-20.aspx . It looks like you use "localhost" as your SMTP server, try the demo and see if it works for you. Good luck!
First, you need to check with your ISP what smtp settings they use (and potentially how many emails you get to send before being blacklisted as spammer, depending on what you're going to use this for...)
Secondly, when you have the correct setting in web.config, you should be able to send to anyone.
EDIT, in response to comment:
To be able to use System.Net.Mail properly, you should add the smtp settings (which you need to get from the ISP/Hosting service) to web.config as follows:
<configuration>
<system.net>
<mailSettings>
<smtp from="test#foo.com">
<network host="smtpserver1" port="25" userName="username"
password="secret" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
</configuration>
See this tutorial for more information.
I don't think that they would limit you to sending mail out only to your discountasp.net account. I would imagine that you might be doing something wrong before I would imagine this is a limitation to discountasp.net.
If it does turn out to be a limitation, you should get on the horn with customer service there and have them either clear up the confusion for you.
Using System.Net.Mail.MailMessage you should be able to set any SMTP address you want.
Dim message As New MailMessage("address#address.com", "address2#address.com")
message.Subject = "MessageSubject"
message.Body = "MessageBody"
Dim client As New SmtpClient(*EmailServerAddress*)
client.Send(message)
dim mailObj as new MailMessage
mailObj.From = {from address}
mailObj.To = {to address}
mailObj.Subject = {subject}
mailObj.BodyFormat = MailFormat.Html
mailObj.Body = {body of message}
SmtpMail.SmtpServer = {mailserver name or IP}
SmtpMail.Send(mailObj)

SMTPClient Half Working \ Half Not

I am using Microsoft's membership framework on a website. I am able to send password retrieval e-mails, but am unable to send e-mails myself using SMTPClient.
When you configure the SMTP settings in the Web Site Administration Tool, what are the settings that this application give it's SMTPclient?
If I know this, I can duplicate it and hopefully send e-mails.
A few items I've ruled out.
- I'm using port 25, (which is the only one allowed under medium trust).
- This code works on my local system.
I was attempting to pass the values for SMTPClient in with the constructor. What I failed to realize is that SMTPClient apparently automatically pulls the values from web.config and uses those.
By trying to pass my own values (even though they where identical); I inadvertently violated trust levels causing a security exception.
Don't pass in smtp info in the constructor, use web.config to set it up, and there should be no problem in medium trust.
It could be lots of things, from credential problems, DNS issues, or...who knows. Is it unable to send as in you get an error or as in they appear to go but never arrive?
Are you sure the WSA tool is going through SMTPClient, or are you just assuming it (I don't know myself)?
-- MarkusQ
I am getting a Security Exception on
my mail
That sounds like a credentials problem then, or a trust issue. Are you sure you're running at medium (or higher) trust? What's the rest of the error?
-- MarkusQ
Try checking your web.config file: is the WSA tool updating these settings?
This element is under the configuration element
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="you#email.com">
<network
host="your.gateway.com"
userName="your#email.com"
password="your_password"
port="25" />
</smtp>
</mailSettings>
</system.net>

Resources