I have modified the code as below, but gets number of errors like;
- statement cannot appear within a method body. End of statement assume.
- comma or ')' expected
- Name sFrom is not declared
- End Sub must be proceed by a matching 'sub' and
could you please advice me where i am going wrong? Also i don't know what i this
"yourwebemail@yourdomain.com", should be replaced with.
Your support and valuable time is most appreciated,
=====================
</div>
Public
Sub SendMsg(TextBox1.text,
"faezeh@aol.com",
"yourwebemail@yourdomain.com", feedback.text)
If IsValidEmail(sFrom) =
False Then
Exit Sub
End If
Dim oMailMsg
As New System.Net.Mail.MailMessage()
For Each sToAddr
As String
In sTo.Split(",")
If IsValidEmail(sToAddr) =
True Then
oMailMsg.To.Add(
New MailAddress(sToAddr))
End If
Next
oMailMsg.From = New MailAddress(sFrom)
oMailMsg.Subject = sSubject
oMailMsg.Body = sMsg
oMailMsg.IsBodyHtml =
True
Try
Dim client
As New SmtpClient(GetSMTP())
client.Send(oMailMsg)
Catch exc As Exception
sMsg =
"URL - " & HttpContext.Current.Request.Url.ToString & vbCrLf & _
"Browser - " & HttpContext.Current.Request.Browser.Browser.ToString & vbCrLf & _
"Time - " & Now() & vbCrLf & _
"From - " & sFrom & vbCrLf & _
"To - " & sTo & vbCrLf & _
"Stack Trace - " & exc.StackTrace.ToString & vbCrLf & _
"Source - " & exc.Source.ToString & vbCrLf & _
"Message - " & exc.Message.ToString & vbCrLf
If exc.Message.IndexOf("CDO Mess") < 0
Then
'SendMsg(sMsg.ToString, Site_Settings.GetSetting("GroupEMail"), _
' Site_Settings.GetSetting("GroupEMail"), GetApplicationVar("Company Name") & " CDO Error")
End If
Finally
End Try
End Sub
Function IsValidEmail(ByVal email
As String)
As Boolean
Return Regex.IsMatch(email, _
"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")
End Function
End Sub
faezeh
Member
425 Points
224 Posts
Re: How can I send email from ASP.net to an AOL account automatically using VB language?
Mar 23, 2007 05:44 PM|LINK
I have modified the code as below, but gets number of errors like;
- statement cannot appear within a method body. End of statement assume.
- comma or ')' expected
- Name sFrom is not declared
- End Sub must be proceed by a matching 'sub' and
could you please advice me where i am going wrong? Also i don't know what i this "yourwebemail@yourdomain.com", should be replaced with.
Your support and valuable time is most appreciated,
=====================
</div>Public
Sub SendMsg(TextBox1.text, "faezeh@aol.com", "yourwebemail@yourdomain.com", feedback.text) If IsValidEmail(sFrom) = False Then Exit Sub End If Dim oMailMsg As New System.Net.Mail.MailMessage() For Each sToAddr As String In sTo.Split(",") If IsValidEmail(sToAddr) = True ThenoMailMsg.To.Add(
New MailAddress(sToAddr)) End If Next oMailMsg.From = New MailAddress(sFrom)oMailMsg.Subject = sSubject
oMailMsg.Body = sMsg
oMailMsg.IsBodyHtml =
True Try Dim client As New SmtpClient(GetSMTP())client.Send(oMailMsg)
Catch exc As ExceptionsMsg =
"URL - " & HttpContext.Current.Request.Url.ToString & vbCrLf & _ "Browser - " & HttpContext.Current.Request.Browser.Browser.ToString & vbCrLf & _ "Time - " & Now() & vbCrLf & _ "From - " & sFrom & vbCrLf & _ "To - " & sTo & vbCrLf & _ "Stack Trace - " & exc.StackTrace.ToString & vbCrLf & _ "Source - " & exc.Source.ToString & vbCrLf & _ "Message - " & exc.Message.ToString & vbCrLf If exc.Message.IndexOf("CDO Mess") < 0 Then 'SendMsg(sMsg.ToString, Site_Settings.GetSetting("GroupEMail"), _ ' Site_Settings.GetSetting("GroupEMail"), GetApplicationVar("Company Name") & " CDO Error") End If Finally End Try End Sub Function IsValidEmail(ByVal email As String) As Boolean Return Regex.IsMatch(email, _ "^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$") End Function End SubEnd
ClassThank you,
Faezeh.