Error on Sending mail asp.net mvc - asp.net

Hi whenever i am trying to send the mail from my application on account creation i get the following error.
User not local; please try a different path. The server response was: Bad Recipient at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
Smtp settings provided by client is all right.When i replace my smtp setting with gmail smtp settings on web.config mail is going smoothly.but when my smtp setting is set to the smtp setting provided by client above error occurs.
I have the folloeing in my web.config.
<mailSettings >
<smtp deliveryMethod="Network" from="from addressm" >
<network defaultCredentials="true" host="hostname" port="25" userName="username" password="password" />
</smtp>
</mailSettings>

The email address you are using for the To address is does not exist on the SMTP server and was therefore refused.
Make sure you use an email address that exists.
See this forum post for more detail.

Bad Recipient error means that address you want to send some mail does not exist. Check it carefully

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();

The SMTP server requires a secure connection or the client was not authenticated

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. k12sm3795394wby.16
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. k12sm3795394wby.16
Source Error:
I am using createUserWizard.. it has a mailing option in its properties that i set using the designer (VS2010). When I used code it worked!, but with that control it doesnt. I wonder why!!
Here is my web.config file:
<system.net>
<mailSettings>
<smtp from="makovetskiyd#yahoo.co.uk">
<network host="smtp.gmail.com" defaultCredentials="false"
port="587" userName="**********" password="*****"/>
</smtp>
</mailSettings>
</system.net>
But I doubt the control uses that setting.
Gmail requires you to use a secure connection. This can be set in your web.config like this:
<network host="smtp.gmail.com" enableSsl="true" ... />
Gmail is blocking your SQL Server instance from sending emails through it. Once you encounter your error, if you login to gmail and try to compose a message, it'll notify you of an access that it blocked. You just need to tell Gmail that this was ligitimate and to allow future logins from sqlserver.
This should do the trick!

Mailbox unavailable error

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.

Is it possible to send an email via google apps without an ssl cert?

I'm trying to send email via google apps from my asp.net app and am getting the following exception:
{"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at "}
My Web.config has the following values (sorry I couldn't get the XML to display):
<system.net>
<mailSettings>
<smtp from="user#domain.com"
deliveryMethod="Network">
<network host="smtp.gmail.com"
port="587"
userName="user#domain.com"
password="password"
enableSsl="true"/>
</smtp>
</mailSettings>
</system.net>
I'm thinking that this is due to my not having an SSL cert but I'm not sure. Any thoughts?
I have it working this way with one of our gmail account (code is simplified):
SmtpClient client = new SmtpClient("smtp.gmail.com", "smtp.gmail.com");
client.EnableSsl = true;
client.Credentials = new NetworkCredential(userName, userPassword);
client.Send(mail); // mail is of type System.Net.Mail.MailMessage
You could try to send an email with this code and your configuration just to see if you receive the same error message.
Your code should work fine; I use the exact same configuration successfully.
You may have a firewall issue.

Resources