ok, so i took this sample form a site that offered to take the source code for the perpose of learning so i did. except that it is not working on my machine but its running where i got it from (the site).
could you please assist me knowing where the code went wrong?
the code is listed below:
<%@dotnet.itags.org. Page Language="VB" ClientTarget="downlevel" %>
<%@dotnet.itags.org. Import Namespace="System.Web.Mail" %>
<script language="VB" runat="server">
Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
Dim myMessage As New MailMessage
Dim myMail As SmtpMail
Dim strEmail As String
If Page.IsValid() Then
strEmail = txtEmail.Text
myMessage.From = "webmaster@dotnet.itags.org." & Request.ServerVariables("SERVER_NAME")
myMessage.To = strEmail
myMessage.Subject = "E-mail Sample from ASP 101!"
myMessage.Body = "This message was sent from sample code by " & _
"http://www.asp101.com. It is used to show people how " & _
"to send e-mail from an ASP+ page. This mail was sent " & _
"from " & Request.ServerVariables("SERVER_NAME") & ". " & _
vbCrLf & vbCrLf & _
"This email was sent to " & strEmail & "."
' Doesn't have to be local... just enter your
' SMTP server's name or ip address!
myMail.SmtpServer = "localhost"
myMail.Send(myMessage)
frmEmail.Visible = False
lblUserMessage.Text = "Your message has been sent to " & strEmail & "."
End If
End Sub
</script>
<html>
<head>
<title>ASP+ Email Sample</title>
</head>
<body>
<asp:Label id="lblUserMessage" text="Enter your e-mail address:" runat="server" />
<form method="post" id="frmEmail" runat="server">
<asp:TextBox id="txtEmail" size="30" runat="server" />
<asp:RequiredFieldValidator runat="server"
id="validEmailRequired" ControlToValidate="txtEmail"
errormessage="Please enter an email address."
display="Dynamic" />
<asp:RegularExpressionValidator runat="server"
id="validEmailRegExp" ControlToValidate="txtEmail"
ValidationExpression="^[\w-]+@dotnet.itags.org.[\w-]+\.(com|net|org|edu|mil)$"
errormessage="Please enter a valid email address."
Display="Dynamic" />
<asp:Button id="btnSendMail" text="Send Mail!" OnClick="btnSendMail_OnClick" runat="server" />
</form>
</body>
</html>
Thanks,
Rami Wahdan.
Hello,
I'm beginner also, but what I would try is:
Change line:
myMessage.From = "webmaster@." & Request.ServerVariables("SERVER_NAME")
into:
myMessage.From = "your@.email.com"
and delete these lines:
' Doesn't have to be local... just enter your
' SMTP server's name or ip address!
myMail.SmtpServer = "localhost"
Rami,
it would also help if you would paste the exact error you are getting ... that will help in identifying your problem ...
cheers,
erik
ok so the error is:
Server Error in '/ASP.NET/email' Application.
The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for a@.a.com
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.Runtime.InteropServices.COMException: The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for a@.a.com
Source Error:
The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL: |
Stack Trace:
|
Version Information: Microsoft .NET Framework Version:2.0.40607.16; ASP.NET Version:2.0.40607.16
hmm, the error seems rather clear, what exactly did you do to solve it?
>The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for a@.a.com
this means that the address you are sending to (a@.a.com) does not exist ...
to prevent this error to cause this page to display, you could add a Try ... Catch ... End Try statement around myMail.send(myMessage), like this:
Try
myMail.Send(myMessage)
Catch ex as Exception
End Try
Mind you, this only prevents the application to stop on the error, you should add code to handle the error properly
HTH
cheers,
erik
0 comments:
Post a Comment