GoDaddy Send Email - asp.net

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

Related

ASP.net Override smtp FROM with different FROM addresses in codebehind

I have a web site where the from mail settings are configured in web.config with
<smtp from="xxx#ourdomain.com">
One of the pages on the website sends e-mails. This page can only be access by certain members who each have their own e-mail address under the domain setup in web.config.
What I would like to be able to do is change the from address based upon the logged in users e-mail address. The code is setup and works fine with 1 exception, when the to recipient receives the e-mail it is listed as from xxx#ourdomain.com on behalf of someuser#ourdomain.com. What I would like to see is for the recipient to see the from as someruser#domain.com.
Is this specific to our email server (Arvixe) or can this be fixed via code? As an alternate is there a way to programmatically change the web.config smtp FROM setting for the individual user? I have to believe that there is another solution out there than purchasing a third party solution such as aspNetEmail.
Web.config settings:
<mailSettings>
<smtp from="xxx#ourdomain.com">
<network host="mail.somehost.com" port="26" userName="xxx#ourdomain.com" password="*****" />
</smtp>
</mailSettings>
Portion of code behind used to send e-mail:
Dim EmailTo As String = item(1).ToString
Dim objMail As New System.Net.Mail.MailMessage
objMail.Attachments.Add(imgAtt)
objMail.Subject = ASPxTextBox1.Text.ToString
objMail.From = New System.Net.Mail.MailAddress("someuser#ourdomain.com")
objMail.Body = message
objMail.IsBodyHtml = True
objMail.To.Clear()
objMail.To.Add(New System.Net.Mail.MailAddress(EmailTo))
smtp.Send(objMail)

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.

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.

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)

Resources