fskilnik
asked on
Sending E-mail through GoDaddy - Part 2
Hi there!
The code presented in my last post here:
https://www.experts-exchange.com/questions/29113749/Sending-E-mail-through-GoDaddy.html
works as expected, but I have to click a button to "make it happen".
What I really need is to call this page from another, so that it goes through the code, sends the email to the user, and goes to another page immediately.
I have tried to adapt my previous code, but it does not work. Error message:
-------------
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: 'txtTo' is not declared. It may be inaccessible due to its protection level.
Source Error:
Line 7:
Line 8: lblMsg1.Text = ""
Line 9: txtTo.Text = " ... "
Line 10: txtFrom.Text = " ... "
Line 11: txtSubject.Text = " ... registration"
-------------
Could you please check the code below and tell me how should it be corrected?
Thanks,
fskilnik.
The code presented in my last post here:
https://www.experts-exchange.com/questions/29113749/Sending-E-mail-through-GoDaddy.html
works as expected, but I have to click a button to "make it happen".
What I really need is to call this page from another, so that it goes through the code, sends the email to the user, and goes to another page immediately.
I have tried to adapt my previous code, but it does not work. Error message:
-------------
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: 'txtTo' is not declared. It may be inaccessible due to its protection level.
Source Error:
Line 7:
Line 8: lblMsg1.Text = ""
Line 9: txtTo.Text = " ... "
Line 10: txtFrom.Text = " ... "
Line 11: txtSubject.Text = " ... registration"
-------------
Could you please check the code below and tell me how should it be corrected?
Thanks,
fskilnik.
<%@ IMPORT namespace="System.Web.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="VB" runat="server">
Sub Page_Load()
lblMsg1.Text = ""
txtTo.Text = " ... "
txtFrom.Text = " ... "
txtSubject.Text = " ... registration"
txtBody.Text = txtBody.Text & vbCrlf & ""
txtBody.Text = txtBody.Text & "Thanks for registering.
txtBody.Text = Replace(txtBody.Text,vbCrlf,"<br>")
txtPriority.Text = "Normal"
' Name of relay mail server in your domain.
txtMailServer.Text = "dedrelay.secureserver.net"
Dim sTo As String, sFrom As String, sSubject As String
Dim sBody As String, sPriority As String, sMailServer As String
Dim iLoop1 As Integer
sTo = Trim(txtTo.Text)
sFrom = Trim(txtFrom.Text)
sSubject = Trim(txtSubject.Text)
sBody = Trim(txtBody.Text)
sPriority = Trim(txtPriority.Text)
sMailServer = Trim(txtMailServer.Text)
Dim MyMail As MailMessage = New MailMessage()
MyMail.From = sFrom
MyMail.To = sTo
MyMail.Subject = sSubject
MyMail.Body = sBody
Select Case UCase(sPriority)
Case "HIGH" : MyMail.Priority = MailPriority.High
Case "LOW" : MyMail.Priority = MailPriority.Low
Case Else : MyMail.Priority = MailPriority.Normal
End Select
SmtpMail.SmtpServer = sMailServer
SmtpMail.Send(MyMail)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ASP.NET sending e-mail</title>
</head>
<body>
<p><asp:Label id="lblMsg1" runat="server"/></p>
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you should be using visual studio to edit this and also have the code behind
ASKER
Hi, David!
Thanks for your time and help!
I created a page with your code (only), and tried to run without success.
Error message:
-------------------------- ---------- ---------- ---------- ---
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls .Label'.
Source Error:
Line 7: Sub Page_Load()
Line 8:
Line 9: lblMsg1 = ""
Line 10:
Line 11: From = " ... "
-------------------------- ---------- ---------- ---------- ---------- ---------- --
The red line in the error message points to Line 9 above.
(Thanks for the Visual Studio suggestion.)
Thanks for your time and help!
I created a page with your code (only), and tried to run without success.
Error message:
--------------------------
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls
Source Error:
Line 7: Sub Page_Load()
Line 8:
Line 9: lblMsg1 = ""
Line 10:
Line 11: From = " ... "
--------------------------
The red line in the error message points to Line 9 above.
(Thanks for the Visual Studio suggestion.)
label1.text = lblMsg1
ASKER
Hi, David.
I am used to ASP, only. I don´t know if I have to define the label1 first, for instance.
I am used to ASP, only. I don´t know if I have to define the label1 first, for instance.
Yes you have to define label1
If I was you I'd start a new empty web project, use the design view put your controls.. double click on a control to manage the control
If I was you I'd start a new empty web project, use the design view put your controls.. double click on a control to manage the control
ASKER
I agree, David.
Let me tell you my history, in short. I am a math teacher, and for the last ten years, at least, I started to create (program) an online course for my students. I knew NOTHING of computing, because the only course I did was BASIC, when I was 13 years old. (I am almost 50.)
Problems were always in front of me, not waiting till I learned what I needed to solve them. To be honest, I know nothing of Javascript, nothing of ASP, nothing of CSS, nothing of database management, etc, but still... I have more than 300 pages (easy) working, using all that, in a SQL Server database... what I am trying to tell you is that my time was ALWAYS spent solving the problem I had in my situation, because I could not have an "academic" learning, so to speak. I know this is not the clever way of doing things but... it worked and, believe me, I have an excellent course!!
Let me tell you my history, in short. I am a math teacher, and for the last ten years, at least, I started to create (program) an online course for my students. I knew NOTHING of computing, because the only course I did was BASIC, when I was 13 years old. (I am almost 50.)
Problems were always in front of me, not waiting till I learned what I needed to solve them. To be honest, I know nothing of Javascript, nothing of ASP, nothing of CSS, nothing of database management, etc, but still... I have more than 300 pages (easy) working, using all that, in a SQL Server database... what I am trying to tell you is that my time was ALWAYS spent solving the problem I had in my situation, because I could not have an "academic" learning, so to speak. I know this is not the clever way of doing things but... it worked and, believe me, I have an excellent course!!
It is easier to have just the html on the .aspx page and everything else that modifies the html on the .aspx.vb page
ASKER
I am not proud of my ignorance, I am proud I am able to adapt what you all help me to do, and I use what I was able to do before, when things get similar to something I did previously... as an example, look at this:
<%
function IsRegularStudent(currUserI D)
Dim rsRegularStudent
Set rsRegularStudent = Server.CreateObject("ADODB .Recordset ")
rsRegularStudent.ActiveCon nection = MM_..._STRING
rsRegularStudent.Source = "select COUNT(MaterialID) AS IsRegular from dbo.OrdersDetails where (MaterialID in ( ... ) AND OrderID in (SELECT TransactionID FROM dbo.Orders where UserID = " & currUserID & " ))"
rsRegularStudent.CursorTyp e = 0
rsRegularStudent.CursorLoc ation = 2
rsRegularStudent.LockType = 1
rsRegularStudent.Open()
IsRegularStudent = rsRegularStudent.Fields.It em("IsRegu lar").Valu e
End function
%>
I cannot explain to you what each parameter does, but I know the code works perfectly, and I have dozens that are almost equal to this one, same structure, without really knowing what is going on... but the query, of course, I understand fully... got it?
<%
function IsRegularStudent(currUserI
Dim rsRegularStudent
Set rsRegularStudent = Server.CreateObject("ADODB
rsRegularStudent.ActiveCon
rsRegularStudent.Source = "select COUNT(MaterialID) AS IsRegular from dbo.OrdersDetails where (MaterialID in ( ... ) AND OrderID in (SELECT TransactionID FROM dbo.Orders where UserID = " & currUserID & " ))"
rsRegularStudent.CursorTyp
rsRegularStudent.CursorLoc
rsRegularStudent.LockType = 1
rsRegularStudent.Open()
IsRegularStudent = rsRegularStudent.Fields.It
End function
%>
I cannot explain to you what each parameter does, but I know the code works perfectly, and I have dozens that are almost equal to this one, same structure, without really knowing what is going on... but the query, of course, I understand fully... got it?
ASKER
I understand what you say. I have tried to learn ASP.NET in the past, and I remember Visual Studio was great in "separating" codes related to design and programming, etc. I reallly understand your point, anyway.
I cannot explain to you what each parameter does, but I know the code works perfectly, and I have dozens that are almost equal to this one, same structure, without really knowing what is going on.
this happens all of the time.. which is why commenting is so useful. I was hired to change a db4's code and it took me 3 days just to go through the code and find out which variable went where. real pain when you add something and later on find out you break something else totally unrelated. Upon reflection it would have been easier to just rewrite the entire project from scratch.
this happens all of the time.. which is why commenting is so useful. I was hired to change a db4's code and it took me 3 days just to go through the code and find out which variable went where. real pain when you add something and later on find out you break something else totally unrelated. Upon reflection it would have been easier to just rewrite the entire project from scratch.
ASKER
Ok, David. I have been helped here for a long time, and my respect to you, people who are really experts, is really huge.
What I am trying to say is that if, for instance, the "CursorType = 0" has profound implications, it is not my real interest because I do not intend to create sites and programs to other people. If a certain page of mine stops functioning, I will probably suspect that this COULD be the origin of the problem, I would come here, and ask people like you, if the problem may be related to that.
To be really explicit, without any intention to be rude, I do not intend to install Visual Studio at this moment, to start a Hello_World page there, from start, to see all code generated, etc. It´s not my focus at this moment, simple as that.
If you can help me adapting my code, telling me what should be changed, where should I define the label1 that is missed, without having a second page generated by Visual Studio, because I am doing all that in Dreamweaver, even coding, and I know this is not recommended, it would be really great.
If you feel I should do what you suggest, because you don´t want to "spoon feed me", or something similar, I respect that, although I believe I deserve respect for my willing to have things done, even without real intention to become proficient in those skills. It would take a lifetime in any one of them, and neither of them is my focus. I intend to go back to my PhD studies, but first I have to increase my earnings...
What I am trying to say is that if, for instance, the "CursorType = 0" has profound implications, it is not my real interest because I do not intend to create sites and programs to other people. If a certain page of mine stops functioning, I will probably suspect that this COULD be the origin of the problem, I would come here, and ask people like you, if the problem may be related to that.
To be really explicit, without any intention to be rude, I do not intend to install Visual Studio at this moment, to start a Hello_World page there, from start, to see all code generated, etc. It´s not my focus at this moment, simple as that.
If you can help me adapting my code, telling me what should be changed, where should I define the label1 that is missed, without having a second page generated by Visual Studio, because I am doing all that in Dreamweaver, even coding, and I know this is not recommended, it would be really great.
If you feel I should do what you suggest, because you don´t want to "spoon feed me", or something similar, I respect that, although I believe I deserve respect for my willing to have things done, even without real intention to become proficient in those skills. It would take a lifetime in any one of them, and neither of them is my focus. I intend to go back to my PhD studies, but first I have to increase my earnings...
ASKER
Hi, David.
I found a very interesting solution using RAZOR that, seems to me, combine the easiness of one-page-only with the clear programming in the server, although I am far from being able to judge advantages and disadvantages, from a real pro perspective, as it is now more-than-clear.
For the interested readers: https://aspnetfaq.com/sending-email-code-sample-razor-c/
Thank you very much for your time and suggestions. I really understand your points.
(As a math teacher, I also prefer the deep knowledge and clear understanding, to the "do-it-right-suffices" procedures.)
I found a very interesting solution using RAZOR that, seems to me, combine the easiness of one-page-only with the clear programming in the server, although I am far from being able to judge advantages and disadvantages, from a real pro perspective, as it is now more-than-clear.
For the interested readers: https://aspnetfaq.com/sending-email-code-sample-razor-c/
Thank you very much for your time and suggestions. I really understand your points.
(As a math teacher, I also prefer the deep knowledge and clear understanding, to the "do-it-right-suffices" procedures.)