email form using GoDaddy
- I am trying to have a form that a site visitor fills out emailed to the applicable addresses. I am using ASP.NET 2.0 and Expression Web 1. My host is GoDaddy. When I submit the form, I receive the following error - "Mailbox name not allowed. The server response was: sorry, your mail was administratively denied. (#5.7.1)."
Here is the code that I am using. Any help would be greatly appreciated.
<%@ Page masterpagefile="Master.master" language="VB" title="Elitediting" %>
<% @Import Namespace="System.Web.Mail" %>
<script runat="server">
Protected Sub SubmitForm_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsValid Then Exit SubDim SendResultsTo As String = "contactus@elitediting.com"
Dim smtpMailServer As String = "relay-hosting.secureserver.net"
Dim smtpMailServerPort As String = "25"
Dim smtpUsername As String = "contactus@elitediting.com"
Dim smtpPassword As String = "********"
Dim MailSubject As String = "Contact Us Form"Try
Dim txtQ As TextBox = Me.FormContent.FindControl("TextBoxQ")
If txtQ IsNot Nothing Then
Dim ans As String = ViewState("hf1")
If ans.ToLower <> txtQ.Text.ToLower Or ans.ToUpper <> txtQ.Text.ToUpper Then
Me.YourForm.ActiveViewIndex = 3
Exit Sub
End If
End IfDim FromEmail As String = SendResultsTo
Dim msgBody As StringBuilder = New StringBuilder()
Dim sendCC As Boolean = False
For Each c As Control In Me.FormContent.Controls
Select Case c.GetType.ToString
Case "System.Web.UI.WebControls.TextBox"
Dim txt As TextBox = CType(c, TextBox)
If txt.ID.ToLower <> "textboxq" Then
msgBody.Append(txt.ID & ": " & txt.Text & vbCrLf & vbCrLf)
End If
If txt.ID.ToLower = "email" Then
FromEmail = txt.Text
End If
If txt.ID.ToLower = "subject" Then
MailSubject = txt.Text
End If
Case "System.Web.UI.WebControls.CheckBox"
Dim chk As CheckBox = CType(c, CheckBox)
If chk.ID.ToLower = "checkboxcc" Then
If chk.Checked Then sendCC = True
Else
msgBody.Append(chk.ID & ": " & chk.Checked & vbCrLf & vbCrLf)
End If
Case "System.Web.UI.WebControls.RadioButton"
Dim rad As RadioButton = CType(c, RadioButton)
msgBody.Append(rad.ID & ": " & rad.Checked & vbCrLf & vbCrLf)
Case "System.Web.UI.WebControls.DropDownList"
Dim ddl As DropDownList = CType(c, DropDownList)
msgBody.Append(ddl.ID & ": " & ddl.SelectedValue & vbCrLf & vbCrLf)
End Select
Next
msgBody.AppendLine()
msgBody.Append("Browser: " & Request.UserAgent & vbCrLf & vbCrLf)
msgBody.Append("IP Address: " & Request.UserHostAddress & vbCrLf & vbCrLf)
msgBody.Append("Server Date & Time: " & DateTime.Now & vbCrLf & vbCrLf)Dim myMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
myMessage.To.Add(SendResultsTo)
myMessage.From = New System.Net.Mail.MailAddress(FromEmail)
myMessage.Subject = MailSubject
myMessage.Body = msgBody.ToString
myMessage.IsBodyHtml = False
If sendCC Then myMessage.CC.Add(FromEmail)
Dim basicAuthenticationInfo As New System.Net.NetworkCredential(smtpUsername,smtpPassword)
Dim MailObj As New System.Net.Mail.SmtpClient(smtpMailServer,smtpMailServerPort)
MailObj.Credentials = basicAuthenticationInfo
MailObj.Send(myMessage)Me.YourForm.ActiveViewIndex = 1
Catch ex As Exception
Me.YourForm.ActiveViewIndex = 2
Response.Write("<span style='color:red'>" & ex.Message & "</span>")
End Try
End Sub</script>
Thank you,
Tim
Answers
- Well it is that simple:
To get it to work all I had to was place it into the button event handler function, which is gets created between the <script></script> tags on the same page. If I was working with an attached file then the code would go into the same event function located in the aspx.cs or aspx.vb depending upon our programin preference.
That was so difficult to explain.
<br/>protected void Button1_Click(object sender, EventArgs e) { const string SERVER = "relay-hosting.secureserver.net"; System.Web.Mail.MailMessage oMail = new System.Web.Mail.MailMessage(); oMail.From = "interested@site.com"; oMail.To = "membership@site.com"; oMail.Subject = "Membership Request"; oMail.BodyFormat = System.Web.Mail.MailFormat.Html; oMail.Body = "<p> Name" + Name.Text + "</p><br/><p>SpouseName" + SpouseName.Text +"</p><br/><p>KidsName" + KidsName.Text + "</p><br/><p>Sent at: " + DateTime.Now; System.Web.Mail.SmtpMail.SmtpServer.Equals(SERVER); System.Web.Mail.SmtpMail.Send(oMail); oMail = null; }<br/><br/>
- Marked As Answer byWill BuffingtonMSFT, ModeratorWednesday, June 24, 2009 9:27 PM
All Replies
- Have you tried asking GoDaddy?
- Yes, a couple of times. They said to change the From address, which did not help.
- I have been fighting with this problem for about 2 weeks now. After much searching & reading I'm not much farther along than I was at the beginning. GoDaddy's support is worthless. If I ever solve this problem, I will make a step by step how to on this forum.
Problem: Created a website using asp.net masterpages. Used Contact Form Generator for Expressions to create a contact form. The form works perfectly if you send an email ONLY thru the GoDaddy system ... one GoDaddy hosted email to another GoDaddy hosted email ... however, it does not work at all if you try sending an email from an outside source such as yahoo, gmail, etc.
GoDaddy says you must use their form mailer (gdform.asp or webmailerform.asp) and register your email with the form mailer through your hosting control center. I did this. This is the smtpMailServer As String = "relay-hosting.secureserver.net." No user name or password is necessary. The instructions to use their form mailer are for an html page only. I created an html page with their instructions and it does work perfectly, but it seems crazy to have an entire website using masterpages & the one page that really could use asp.net features having to be on an html page.
I am at the point that I will use an html page if I have to, but if I do, how do you do things like validate email addresses, put in spam protection, etc.
Can anyone help?
The contact form generator form on the website: http://conciergeserviceofkeywest.com/contact_us.aspx
The code used for the form: http://conciergeserviceofkeywest.com/contact-code.html
Copy of email from GoDaddy Support: http://conciergeserviceofkeywest.com/godaddy-support.html
Thanks for any assistance you can give.
Tami
- Edited byTamiG Thursday, February 12, 2009 8:06 PMfix hyperlink
- TamiG said:I don't use GoDaddy, don't want to and never will (willingly), so I can't help with that part of your question. However, for the above question, the answer is javascript. Google "javascript validation" to find a number of solutions. There are also pre-written frameworks that will do the job for you. Google "javascript validation framework." As for spam control, I think you're probably talking about something like CAPTCHA, for which there are many solutions available on the Web.
<<::snip::>>
I am at the point that I will use an html page if I have to, but if I do, how do you do things like validate email addresses, put in spam protection, etc.
<<::snip::>>Tami
Spam control, CAPTCHA, obfuscation, validation, etc. all exist quite independently of either ASP or ASP.NET, so you have a plethora of options from which to choose your preferred solution. Or, you could just blow off GoDaddy and get a real hosting provider. <g,d,&r>
cheers,
scott
- Take a look at http://by-expression.com/forums/p/14/37.aspx#37 This is the code I used on GoDaddy to get the contact form in the Expression Web Portfolio Starter Kit working about 2 years ago.
MS MVP Expression http://by-expression.com After 4 calls to GoDaddy I have tracked down the issue but do not know how to resolve it easily. It seems that when you publish a ASP forms page with the runat="server" the action gets repopulated with the aspx page.
Example: You code <form method="post" action="_gdform/webformmailer.asp" runat="server"> in expression publish it to the webhost. If you open the page and look at the source code you will see the <form> code is changed to <form method="post" action="page.aspx" id="ASPFORM">.
Does anyone know how or why this occurs or how to fix it?- . . .
8. Find another provider, any provider, besides GoDaddy. - All ASP.NET output to the browser is HTML. ASP.NET runs on the server not in the browser. So doing a view source on the page will always show you HTML and possibly javascript if you are using the dotnet validation controls which validate first client side then a separate server side check.
Did you even look at the link I posted earlier:
Take a look at http://by-expression.com/forums/p/14/37.aspx#37 This is the code I used on GoDaddy to get the contact form in the Expression Web Portfolio Starter Kit working about 2 years ago.
I know the code in that works because I've tested it and just ran another test before writing this post. You would need to change the this.field.text to whatever your form fields are but the part for sending the mail would be the same other than replacing the from with some email address for your domain and who you want to receive the mail on your end in the oMail.Bcc. It does use the relay-hosting.secureserver.net service at GoDaddy so that you can send to any email address not just those in your domain.
FWIW, I don't use the GoDaddy form script first because it is classic asp and not asp.net so you can't use the validation tools in dotnet. Second, because it is limited to sending the results only to the address specified in your control panel so you can't send a confirmation copy and finally because you have very little flexibility in what you do with the results.
MS MVP Expression Tutorials & Help http://by-expression.com and online instructor led Expression Classes- Edited byCheryl D WiseMVPTuesday, April 21, 2009 1:52 PMadded more information
- Yes I have to agree. This has been a very frustrating process and this after being told that they do not make any changes. Well, it's completely BS. The only reason I am with them is the cost. Looking around for another ISP could find one that had windows servers for that 4-5 dollar price point.
Yes I have to agree. This has been a very frustrating process and this after being told that they do not make any changes. Well, it's completely BS. The only reason I am with them is the cost. Looking around for another ISP could find one that had windows servers for that 4-5 dollar price point.
OK, I've just got to come in on this point. How much is your personal/professional time worth? For $10/month or less you can get a shared Windows server, all versions of PHP, ASP, and ASP.NET frameworks, SQL Server and MySQL, etc., basically everything GoDaddy offers and a ton more. And on a yearly plan that comes out to $8.33/month. The price delta is about what a Starbucks coffee once a month would cost you. It sounds to me as if you've already spent several hours dealing with this issue. At a conservative rate of $20/hour for your time, you've already paid for the differential between GoDaddy and a real hosting provider for full year, and then some, and you're still stuck with GoDaddy. Just sayin'...
cheers,
scott- Hi Cheryl,
The issue is that you assume that people understand what type of file to create, where to put that code, or how to reference it once you've created the file. So while you have created some wonderful working code it does me no good because I do not know how to implement it. I am not a professional just an educated hobbyist and web enthusiast. In this instance, I am doing work pro-bono for a local organization and keeping sending low means more money in other places.
- The I suggest that you spend some time learning. Working with forms requires some understanding of how server side code works. The example I give is really quite easy once you have even the slightest understanding of how dotnet works.
There are many free resources on the net including http://w3schools.com which has CSS, HTML and even server side lessons. Microsoft has a ton of resources including videos and tutorials on dotnet available all over the internet starting with http://www.asp.net/LEARN/videos/. Many of them using the free Visual Web Developer Express because Expression Web doesn't have much to help you by way of server side code http://www.microsoft.com/express/vwd/ the two work well together.
Using generators will only get you so far and as you saw leads to lots of fustration.
MS MVP Expression Tutorials & Help http://by-expression.com and online instructor led Expression Classes I have spent plenty of time learning and I completely understand how the code works. What 90% of programmers forget is that those who are self taught have not had the luxury of learn the background and larger picture of how everything interacts. Imagine learning a language one word at a time and never knowing there is actually an alphabet or understanding how sentence structure are formed.
The internet is full of code snippets and it's easy to understand a snippit of code but if you have no understand where to place this useful code that you understand then it's worthless. With the plethora of file types .cs, .ascx, .css, .aspx, .asp, etc... it becomes daunting what kind of file to create and how things interact within the file. My issue is not with understanding your code and making it fit what I need but the reality is I have no knowledge of what to do with it once I've made the changes.
So here is some feedback from someone that would look at your example for help: Yes I saw your example, Yes I understood how to change the code to work for me, but with out understanding what kind of file to create, or futher details I said great looks good but don't know what to do next.
So thanks for the links, I will go off and learn more words and try to piece together a sentence.
That doesn't make sense. I'm self-taught and fully understand the big picture.What 90% of programmers forget is that those who are self taught have not had the luxury of learn the background and larger picture of how everything interacts. Imagine learning a language one word at a time and never knowing there is actually an alphabet or understanding how sentence structure are formed.
--
Chris Hanscom - Microsoft MVP
Resource Center | Veign's Blog | Web Development Help
Good for you! I am glad you've achieved this. I on the other hand am still trying to figure it out. So maybe you can help me understand on what I should do with Cheryl's code? Because I have yet to figure it out.
That doesn't make sense. I'm self-taught and fully understand the big picture.What 90% of programmers forget is that those who are self taught have not had the luxury of learn the background and larger picture of how everything interacts. Imagine learning a language one word at a time and never knowing there is actually an alphabet or understanding how sentence structure are formed.
--
Chris Hanscom - Microsoft MVP
Resource Center | Veign's Blog | Web Development Help- Follow her advice and read up on the technology. Learn the big picture.
--
Chris Hanscom - Microsoft MVP
Resource Center | Veign's Blog | Web Development Help As representatives of MS I would expect more.... maybe answer my question of how to implement the code but I guess not.... Good day.
- I'm not a representative of MS nor do i have any ties to MS. I am just a forum member who gives his time freely to answer questions.
You need to step back and do some learning. People can only help so much. Step back, learn the technology (read up on the links Cheryl posted) then review your question.
Everyone here is donating there time. You have to be prepared to put the hours in learning.
--
Chris Hanscom - Microsoft MVP
Resource Center | Veign's Blog | Web Development Help - Man I would be happy with an answer like you have to place the code into a aspx.cs file and reference it as a submit button action. I am not looking for a step by step tutorial. I just haven't grasp the concept of how the files all get reference at this point. I may have unintentionally made myself out to be completely oblivious but I'm not. I am trying to make a point that not everyone in these forms has a full understanding when you see a snipit of code on where to place it.
- I am using GoDaddy for some time now and emailing user creation details back to user,
copied some code from MS sample projects and adapted to suit.
Don't know if this will help for your case but here is some of the code that works for me:
<asp:CreateUserWizard runat="server" id="CreateUserWizard1" BorderWidth="1px" BorderColor="#E6E2D8" BorderStyle="Solid" BackColor="#E3EAEB" Font-Size="X-Small" Font-Names="Verdana" CancelDestinationPageUrl="users.aspx" LoginCreatedUser="False" FinishDestinationPageUrl="users.aspx" ContinueDestinationPageUrl="users.aspx" onsendingmail="SendingMail">
...............
<MailDefinition From="noreply@yourdomain.com" BodyFileName="MailFile.txt" ></MailDefinition>
..............
</asp:CreateUserWizard>
public void SendingMail(object sender, MailMessageEventArgs e)
{
// Set MailMessage fields.
e.Message.IsBodyHtml = false;
e.Message.Subject = "New user details for Yourdomain.com secure access.";
e.Message.Body = e.Message.Body.Replace("<%PasswordQuestion%>", CreateUserWizard1.Question);
e.Message.Body = e.Message.Body.Replace("<%PasswordAnswer%>", CreateUserWizard1.Answer);
}
} - I don't know what "programmers" you are talking to but I for one am "self-taught" learning from some of those resources I mentioned and a lot of other tutorials. It doesn't take knowing the "big picture" to understand what the code bits I used do and if you learn anything about forms processing in dotnet then "where" it goes is obvious and not part of any big picture. The "big picture" is when you are architecting a site, something that I've also learned how to do by the seat of my pants.
As for the code in the link it is how to get the contact form that comes in one of the Expression starter kits to actually send email from GoDaddy since the code included in the starter kit doesn't work on GoDaddy servers. The quick way to understand where it goes is to look at the stareter kits. The oSomething are variables either from the form or from the dotnet framework and where it goes depends on how you created your form and whether you are using code behind or on page processing. That choice depends on how you are working on the site and how much of your code you want to be reusable on multiple pages.
Oh and I'll jump ahead and repsond to your comment "as a representative of MS" - I am not a representative of MS, nor is Chris or any other MVP. An MVP is an award given to people who voluntarily spend time answering questions on MS programs. We are not employees of MS and in fact Microsoft employees are not eligible to receive the award. Look at http://mvp.support.microsoft.com/ for information on the MVP award.
MS MVP Expression Tutorials & Help http://by-expression.com and online instructor led Expression Classes - No, I'm sorry but the answer isn't that simple.
Unlike Classic ASP or PHP you can't just say "put this code on a page called mail.asp and use "<form action="mail.asp" method="post">" and everything will work. THAT is why we listed places for you to learn the basic concepts so you can determine whether you should be using aspx, aspx.cs, aspx.vb, ascx, or something else.
That is why you were given resources for learning the basics since just because you can sort of use a snippet doesn't mean that you should when you don't have an understanding of basic concepts.
MS MVP Expression Tutorials & Help http://by-expression.com and online instructor led Expression Classes - Well it is that simple:
To get it to work all I had to was place it into the button event handler function, which is gets created between the <script></script> tags on the same page. If I was working with an attached file then the code would go into the same event function located in the aspx.cs or aspx.vb depending upon our programin preference.
That was so difficult to explain.
<br/>protected void Button1_Click(object sender, EventArgs e) { const string SERVER = "relay-hosting.secureserver.net"; System.Web.Mail.MailMessage oMail = new System.Web.Mail.MailMessage(); oMail.From = "interested@site.com"; oMail.To = "membership@site.com"; oMail.Subject = "Membership Request"; oMail.BodyFormat = System.Web.Mail.MailFormat.Html; oMail.Body = "<p> Name" + Name.Text + "</p><br/><p>SpouseName" + SpouseName.Text +"</p><br/><p>KidsName" + KidsName.Text + "</p><br/><p>Sent at: " + DateTime.Now; System.Web.Mail.SmtpMail.SmtpServer.Equals(SERVER); System.Web.Mail.SmtpMail.Send(oMail); oMail = null; }<br/><br/>
- Marked As Answer byWill BuffingtonMSFT, ModeratorWednesday, June 24, 2009 9:27 PM
- Agree's with Rollo1002
you would have less headaches on trying to follow up on things.
reasons like this is why i stick with php and will never use asp.
when i ran a windows server ya .net looks very appealing.
but getting the right answers when you need them instead of spending 30+hrs reading.
is pretty hard to find decent people to help.
this is why most forums have issues.
thanks rollo for the tip and thanks cheryl for a basic start.
if your going to answer you should atleast give more detail what to do with the final.
even if its a link to the answer to make someone read. instead of dig for the answer.
Sorry if this is rude. but Like me Was asked to do something to fix a issue due to a new host.
If Rollo didnt figure it out i would have beat my head and rewrote there whole site. instead of wasting time with asp.
[Snip] Edited for Decorum- Edited byWill BuffingtonMSFT, ModeratorWednesday, June 24, 2009 9:12 PMDecorum
- For 2 cents worth, I repurposed an ancient IBM desktop with Linux and have been using it as my own web host for a long time successfully. I could use ASP via the mono-project but I use PHP for my server side code as its well supported with a tons of helpful code snippets all over.
Given that I am the administrator, I have learned a spectacular amount of IT related skills. This can only make me more useful in the long run.
I use mailto:me@comain.com and it works fine.
If I resort to a form, I simply feed it to a text file or other container and go from there. I tend to avoid SQL and use CSV files to open the data with Excel or something like that.
Vote if helpful, I am running for Office (joke), also mark questions answered. IT/Developer, Windows/Linux/Whatever I need a new web server, the antique IBM 300GL has a 137GB disk limit, for my chess site. My server's disk finally croaked, I am out of work, I need to get a new server as the old IBM is past its prime. Well it is that simple:
To get it to work all I had to was place it into the button event handler function, which is gets created between the <script></script> tags on the same page. If I was working with an attached file then the code would go into the same event function located in the aspx.cs or aspx.vb depending upon our programing preference.
That was so difficult to explain.
protected void Button1_Click(object sender, EventArgs e) { const string SERVER = "relay-hosting.secureserver.net"; System.Web.Mail.MailMessage oMail = new System.Web.Mail.MailMessage(); oMail.From = "interested@site.com"; oMail.To = "membership@site.com"; oMail.Subject = "Membership Request"; oMail.BodyFormat = System.Web.Mail.MailFormat.Html; oMail.Body = "<p> Name" + Name.Text + "</p><br/><p>SpouseName" + SpouseName.Text +"</p><br/><p>KidsName" + KidsName.Text + "</p><br/><p>Sent at: " + DateTime.Now; System.Web.Mail.SmtpMail.SmtpServer.Equals(SERVER); System.Web.Mail.SmtpMail.Send(oMail); oMail = null; }<br/><br/>
Not sure if updating to II7 or some other backend update caused by GoDaddy has caused an issue not but the code above needs to be change. The System.Web.Mail is no longer working (at least for me it stopped) and had to be changed to use System.Net.Mail. Don't fret here is the new code as there are a few other items that change with the new method:
protected void Button1_Click(object sender, EventArgs e)
{
const string SERVER = "relay-hosting.secureserver.net";
System.Net.Mail.MailMessage oMail = new System.Net.Mail.MailMessage();oMail.To.Add(Email.Text); //email.text is a text box in my form where I am collecting the email
oMail.From = new System.Net.Mail.MailAddress("name@yoursite.xxx");
oMail.Bcc.Add("name@yoursite.xxx"); //I use the BCC to send me a copy of the form-mailer
oMail.Subject = "Subject of Mail Here";oMail.IsBodyHtml = true; //will send an HTML formated email
// Below is the message body surround text with quotes " " and as you can see I have radio button and information from text boxes too. The break return in quotes help with formating of the message
oMail.Body = "Membership: " + RadioButtonMembership.SelectedValue + "<br/>MemberType: "
+ RadioButtonMembershipType.SelectedValue + "<br/>Payment Method: " + Payment.SelectedValue +"<br/>First Name: "
+ FName.Text + "<br/> Last Name: " + LName.Text + "<br/> Spouse Name: " + SpouseName.Text + "<br/>Kids Name: " + KidsName.Text
+ "<br/>Address: " + Address.Text + "<br/>Address1: " + Address1.Text + "<br/>City: " + City.Text + " State: " + State.SelectedValue
+ " Zip: " + Zip.Text +"<br/>Phone: " + PhoneNumber.Text + "<br/> Email: " + Email.Text + "<br/> Sent at: " + DateTime.Now;System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(SERVER);
smtp.Send(oMail);oMail = null;
}- Yes for Godaddy hosting it is a problem.But i have solved this problem in this way.I have a button in my 'Contact Us' page...in 'Send' button click event i have written this code..hope it will work..Notice that you have to mention the "To" and "From" (who send the mail and receiver mail) will be same.yes you just append the sender mail id with 'body',so receiver can see ..who sent the mail.but 'To' and 'From' will be same as ur domain mail address.
Example:if your mail id in domain like this:info@domain.com
so for this case 'Mail To':info@domain.com
'Mail From':info@domain.com
You just append the orginal sender mail id with body..not in Mail From option.
Here is the code:
protected void btnSend_Click(object sender, EventArgs e)
{
lblAlert.Visible = false;
string subject = txtSubject.Text.Trim();
string _mailfromemail = txtEmail.Text.Trim();
string _mailto = "info@domain.com";
string message = txtMessage.Text.Trim();
StringBuilder sb = new StringBuilder();
sb.Append(message);
sb.Append(" <br/> ");
sb.Append("\n");
sb.Append(" <br/> ");
sb.Append("Mail Sent By:");
sb.Append(" ");
sb.Append(_mailfromemail);
string body = sb.ToString();
if (string.IsNullOrEmpty(body))
{
lblAlert.Visible = true;
lblAlert.Text = "Plese mention the mail body.";
return;
}
bool status = SendEmail(_mailto,_mailfromemail, subject, body);
if (status)
{
lblAlert.Visible = true;
lblAlert.Text = "your mail has been sent successfully";
txtSubject.Text = "";
txtEmail.Text = "";
txtMessage.Text = "";
}
else
{
lblAlert.Visible = true;
lblAlert.Text = "sorry! your mail could not be sent";
}
}
static bool SendEmail(string ToAddr,string senderEmail, string Subject, string Body)
{
bool result;
try
{
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("info@domain.com", senderEmail);
Msg.Subject = Subject;
Msg.Body = Body;
Msg.To.Add(ToAddr);
Msg.BodyEncoding = System.Text.Encoding.UTF8;
Msg.Priority = MailPriority.High;
Msg.IsBodyHtml = true;
SmtpClient SMTP = new SmtpClient("relay-hosting.secureserver.net", 25);
SMTP.Send(Msg);
result = true;
}
catch (Exception Err)
{
result = false;
}
return result;
}
Yes for Godaddy hosting it is a problem.But i have solved this problem in this way.I have a button in my 'Contact Us' page...in 'Send' button click event i have written this code..hope it will work..Notice that you have to mention the "To" and "From" (who send the mail and receiver mail) will be same.yes you just append the sender mail id with 'body',so receiver can see ..who sent the mail.but 'To' and 'From' will be same as ur domain mail address.
Hi,
Example:if your mail id in domain like this:info@domain.com
so for this case 'Mail To':info@domain.com
'Mail From':info@domain.com
You just append the orginal sender mail id with body..not in Mail From option.
Here is the code:
protected void btnSend_Click(object sender, EventArgs e)
{
lblAlert.Visible = false;
string subject = txtSubject.Text.Trim();
string _mailfromemail = txtEmail.Text.Trim();
string _mailto = "info@domain.com";
string message = txtMessage.Text.Trim();
StringBuilder sb = new StringBuilder();
sb.Append(message);
sb.Append(" <br/> ");
sb.Append("\n");
sb.Append(" <br/> ");
sb.Append("Mail Sent By:");
sb.Append(" ");
sb.Append(_mailfromemail);
string body = sb.ToString();
if (string.IsNullOrEmpty(body))
{
lblAlert.Visible = true;
lblAlert.Text = "Plese mention the mail body.";
return;
}
bool status = SendEmail(_mailto,_mailfromemail, subject, body);
if (status)
{
lblAlert.Visible = true;
lblAlert.Text = "your mail has been sent successfully";
txtSubject.Text = "";
txtEmail.Text = "";
txtMessage.Text = "";
}
else
{
lblAlert.Visible = true;
lblAlert.Text = "sorry! your mail could not be sent";
}
}
static bool SendEmail(string ToAddr,string senderEmail, string Subject, string Body)
{
bool result;
try
{
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("info@domain.com", senderEmail);
Msg.Subject = Subject;
Msg.Body = Body;
Msg.To.Add(ToAddr);
Msg.BodyEncoding = System.Text.Encoding.UTF8;
Msg.Priority = MailPriority.High;
Msg.IsBodyHtml = true;
SmtpClient SMTP = new SmtpClient("relay-hosting.secureserver.net", 25);
SMTP.Send(Msg);
result = true;
}
catch (Exception Err)
{
result = false;
}
return result;
}
This code looks great, but i keep getting an error. (Mailbox name not allowed. The server response was: sorry, relaying denied from you location [**.***.**.***] (#5.7.1)")
I played with this all day yesterday and kept on getting error massages like this and got now where.
Is this code still working for somebody else or is it Godaddy that is the problem ?
I regret starting with them already.Rollo1002,I like your solution but I am hoping you can repost it in VB if all possible, I am having the same problem and everything I tried will not work. please consider a simple solution where you show the entire code. I have a button in my master page that take me to an aspx page that all I want is for enter the sender email and the comment and pusha button to to send the email to my unfotuntaly "godaddy" web mail site. thank you and for anyone else who want to jump in on this thread.
also do the buton event handler need to be in the <script> section? and yes I am newby to dot net.
Abe- Here's an idea--just leave GoDaddy. Hosting's cheap, and there are better hosts all over the place. Even if you left early, you wouldn't be out much money. I move every client who comes to me off of GoDaddy when I re-do their site.
- thanks for the reply, unfortunatly this a a friend for mine I am helping with her website, I will never host with godaddy just from the all around bad and cheap reputation.
- Give me a day to work out the solution as I am just getting back from vacation and catching up on a few other things. I will try to provide a solution in VB. After doing much research on this the issue is not a GoDaddy specific issue but a more improved way that MS servers are handling post back events. You will need to make these changes eventually no matter where you host as upgrades to the hosting servers are conducted.
- I'll look forward to seeing Rollo1002's code. Just a heads up but make sure you include the godaddy anti-spam ibits of their relay server and whatever else they may require.
MS MVP Expression Tutorials & Help http://by-expression.com and online instructor led Expression Classes Private Function SendMail() As Boolean
You cannot use use this to debug. If you want to test it out to have to upload it to godaddy server first. Thats the mistake I made, I did not know that you could not test sending an email from godaddy servers from debugger. So the code above works perfect for me. Where I have put "testemail@godaddy.ca" put in the email address that you want the emails to be sent to. I use the same email for To: and From: then the email address that the user types in I just add that as part of the subject. I have lost alot of tears and said some really bad words trying to figure this out, and the only thing that i was missing was that you have to upload it to there servers first like i mentioned above. If the above code is causing trouble please let me know.
Try
Dim SMTP As New SmtpClient
Dim MailMsg As New MailMessage
Dim MailFrom As New MailAddress("testemail@godaddy.ca")
Dim MailTo As New MailAddress("testemail@godaddy.ca")
Dim HostServer As String = "relay-hosting.secureserver.net"
MailMsg.From = MailFrom
MailMsg.To.Add(MailTo)
MailMsg.Subject = txtName.Text & " " & txtSubject.Text.Trim
MailMsg.Body = "Sent at: " & DateTime.Now & vbNewLine _
& txtEmailAddress.Text & vbNewLine _
& txtBody.Text.Trim
MailMsg.IsBodyHtml = True
MailMsg.Priority = MailPriority.High
SMTP.Host = HostServer
SMTP.Send(MailMsg)
SendMail = True
Catch ex As Exception
SendMail = False
End Try
Return SendMail
End Function
Protected Sub cmdSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSend.Click
If txtEmailAddress.Text <> "" And txtName.Text <> "" And txtBody.Text <> "" Then
If SendMail() = False Then
txtBody.BackColor = Drawing.Color.Red
txtEmailAddress.BackColor = Drawing.Color.Red
txtSubject.BackColor = Drawing.Color.Red
txtName.BackColor = Drawing.Color.Red
txtBody.Text = "There was an error sending your comment. Please make sure that all the fields are filled in correctly then try again."
Else
Response.Redirect("HomePage.aspx")
End If
Else
If txtBody.Text = Nothing Then
txtBody.BackColor = Drawing.Color.Red
End If
If txtEmailAddress.Text = Nothing Then
txtEmailAddress.BackColor = Drawing.Color.Red
End If
If txtName.Text = Nothing Then
txtName.BackColor = Drawing.Color.Red
End If
If txtSubject.Text = Nothing Then
txtSubject.BackColor = Drawing.Color.Red
End If
End If
End Sub
- Edited bybguenther Monday, November 09, 2009 1:26 PMCode layout
You cannot use use this to debug. If you want to test it out to have to upload it to godaddy server first. Thats the mistake I made, I did not know that you could not test sending an email from godaddy servers from debugger. So the code above works perfect for me. Where I have put "testemail@godaddy.ca" put in the email address that you want the emails to be sent to. I use the same email for To: and From: then the email address that the user types in I just add that as part of the subject. I have lost alot of tears and said some really bad words trying to figure this out, and the only thing that i was missing was that you have to upload it to there servers first like i mentioned above. If the above code is causing trouble please let me know.
It sould be noted that this may not be unique to GoDaddy, at least in some of the symptoms. Trying to test SMTP send from the local system is problematic for several reasons. To my knowledge, neither the VWD nor the EW development server is configured for or supports SMTP. And if you set up an IIS-based Web, or Apache/PHP, either must also be properly set up for SMTP and the correct credentials used.
Finally, and most problematic, these days most ISPs (including mine) block all email relays to prevent SPAM. Attempting to send an email from your local SMTP server, through theirs, on your regular ISP service account, will only earn you a bounce message, 505 if memory serves, stating that relays are not permitted. In a way, that's actually a successful test, since it confirms that the message did get sent and went at least as far as the ISP's server.
In the current instance, and perhaps others, as well, there are also the unique requirements of a particular provider to account for, so I would say that in the general case you should always try to test from your provider's servers, both to account for these other factors and because, when you come down to it, that's where it will be running when active anyway, so you get the most accurate testing environment that way.
cheers,
scott
Plural's don't have apostrophe's. It seem's sometime's that any word's ending in "s" get a gratuitous apostrophe. Apostrophe's are used to indicate possessive's and elision's (contraction's or abbreviation's).I am not going to reinvent the wheel if this works.
For additional detail for those that need it you would either place this code in a "code behind file" a file ending with .aspx.vb or within the <script></script> tags of the <filename>.aspx of the form page.
To get this exact code to run in the <filename>.aspx page you will need a button with id named "cmdSend_Click" to get the mail to send when the user click the button.
Changes you can or will need to make are:
Dim MailFrom As New MailAddress(testemail@godaddy.ca) // Change this email address to yours
Dim MailTo As New MailAddress(testemail@godaddy.ca) // Change this email address where you want to receive the form
MailMsg.Subject = txtName.Text & " " & txtSubject.Text.Trim // You can either pull the information from a form field as shown or can be hard fixed
MailMsg.Body = "Sent at: " & DateTime.Now & vbNewLine _
& txtEmailAddress.Text & vbNewLine _
& txtBody.Text.Trim
// You will want to change this information depending upon your form and the information you are relaying the current code pulls from a textbox on the <filename>.aspx page named txtEmailAddress and txtBody
One thing to note is that the above code uses validation before sending the form this is not necessary if you are using aspx validation controls. If you are then delete everything in the cmdSend_Click() function and type SendMail() then Response.Redirect("<yourconfirmationpage>.aspx")- Edited byRollo1002 Monday, November 09, 2009 4:08 PMgrammer changes
- You guys are awsome, I will try it and let you know, thank you
- Like I said you guys are awsome, bguenther example was a cut and past and work from the first time.
Thanks to all of you, Cheryl D Wise, bguenther, paladyn and Rollo1002 all comments and advise will be take seriously in the final version.
Abe
Test Version
Protected
Sub cmdSend_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdSend.Click
'If txtEmailAddress.Text <> "" And txtName.Text <> "" And txtBody.Text <> "" Then
'If SendMail() = False Then
'txtBody.BackColor = Drawing.Color.Red
'txtEmailAddress.BackColor = Drawing.Color.Red
'txtSubject.BackColor = Drawing.Color.Red
'txtName.BackColor = Drawing.Color.Red
'txtBody.Text = "There was an error sending your comment. Please make sure that all the fields are filled in correctly then try again."
'Else
'Response.Redirect("HomePage.aspx")
'End If
'Else
'If txtBody.Text = Nothing Then
'txtBody.BackColor = Drawing.Color.Red
'End If
'If txtEmailAddress.Text = Nothing Then
'txtEmailAddress.BackColor = Drawing.Color.Red
'End If
'If txtName.Text = Nothing Then
' txtName.BackColor = Drawing.Color.Red
' End If
'If txtSubject.Text = Nothing Then
'txtSubject.BackColor = Drawing.Color.Red
'End If
'End If
SendMail()
End Sub
Private Function SendMail() As Boolean
Try
Dim SMTP As New SmtpClient
Dim MailMsg As New MailMessage
Dim MailFrom As New MailAddress("webmaster@zzzzzzzbestfriend.com")
Dim MailTo As New MailAddress("webmaster@zzzzzzzbestfriend.com")
Dim HostServer As String = "relay-hosting.secureserver.net"
MailMsg.From = MailFrom
MailMsg.To.Add(MailTo)
MailMsg.Subject =
"My Mail Subject"
MailMsg.Body =
"Sent at: My Mail Body " '& DateTime.Now & vbNewLine _& txtEmailAddress.Text & vbNewLine _& txtBody.Text.Trim
MailMsg.IsBodyHtml =
True
MailMsg.Priority = MailPriority.High
SMTP.Host = HostServer
SMTP.Send(MailMsg)
SendMail =
True
Catch ex As Exception
SendMail =
False
End Try
Return SendMail
End Function

