In order for my users to send me their comments, I have placed a button labelled as ‘send your message’ and a text box on my webpage.
I need to code the button such that when a user click on button (‘send your message’) the content of the textbox is emailed to me automatically;
i.e. my email address at faezeh@aol.com
I simply want to receive the content of the textbox, is there any way that I could do this in Visual Studio 2005. I have never used the email
function or code, thus, I would be most grateful it if you could advice me.
*I am using Visual Studio 2005 and Visual Basic Language
Here is the generic method I defined that I pass all my e-mail too. You need to supply the message, the textbox in your case, the to address (fazeh@aol.com in your case), the from address (most likely you will need this
to be from the e-mail address for your site because of the way e-mail is screened by aol) and a subject. You could additionally add priority, etc. If you want to send to multiple address you can pass that to the sTo parameter as a comma separated series.
The IsValidEmail is a utility method I have defined that uses a regular expression to validate the address.
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
Please could you help me, as i really need this function for my project and the deadline is approaching; i have asked about emailing number of times before, but was never able to actually implement it.
Email Form Information via Exchange serveremail send smtpButton Event OnClicke-mail
Hi,
In the method's declaration, you should use a argument variable not the value to be passed in.
Public Sub SendMsg(TextBox1.text, "faezeh@aol.com", "yourwebemail@yourdomain.com", feedback.text)
->
public sub SendMsg(byval var1 as string, byval sfrom as string, byval sto as string, byval sfeedback)
Your problems are mainly about the incorrect syntax, I believe visual studio will showdetail information about them and give you more specific ideas of how to correcting them.
faezeh
Member
425 Points
224 Posts
How can I send email from ASP.net to an AOL account automatically using VB language?
Mar 23, 2007 12:28 PM|LINK
In order for my users to send me their comments, I have placed a button labelled as ‘send your message’ and a text box on my webpage.
I need to code the button such that when a user click on button (‘send your message’) the content of the textbox is emailed to me automatically; i.e. my email address at faezeh@aol.com
I simply want to receive the content of the textbox, is there any way that I could do this in Visual Studio 2005. I have never used the email function or code, thus, I would be most grateful it if you could advice me.
*I am using Visual Studio 2005 and Visual Basic Language
button email form email send smtp email repeater gmail content
Thank you,
Faezeh.
yanku
Member
18 Points
116 Posts
Re: How can I send email from ASP.net to an AOL account automatically using VB language?
Mar 23, 2007 12:58 PM|LINK
Hi,
see the below URL.
http://forums.asp.net/thread/1633637.aspx
Hope this help.
Regards,
Yanku
docluv
Star
12685 Points
2005 Posts
ASPInsiders
MVP
Re: How can I send email from ASP.net to an AOL account automatically using VB language?
Mar 23, 2007 12:59 PM|LINK
Here is the generic method I defined that I pass all my e-mail too. You need to supply the message, the textbox in your case, the to address (fazeh@aol.com in your case), the from address (most likely you will need this to be from the e-mail address for your site because of the way e-mail is screened by aol) and a subject. You could additionally add priority, etc. If you want to send to multiple address you can pass that to the sTo parameter as a comma separated series.
The IsValidEmail is a utility method I have defined that uses a regular expression to validate the address.
<div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas">Public Sub SendMsg(ByVal sMsg As String, _
ByVal sTo As String, ByVal sFrom As String, _
ByVal sSubject As String)
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
<div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas">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
</div></div>e-mail
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 01:48 PM|LINK
My text box is labeled as 'Textbox1' and the 'subject' for the email is 'feedback';
Could you please advice where I should put the textbox name, email address and subject in this code?
Thank you,
Faezeh.
docluv
Star
12685 Points
2005 Posts
ASPInsiders
MVP
Re: How can I send email from ASP.net to an AOL account automatically using VB language?
Mar 23, 2007 02:56 PM|LINK
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.
faezeh
Member
425 Points
224 Posts
Re: How can I send email from ASP.net to an AOL account automatically using VB language?
Mar 24, 2007 08:56 AM|LINK
Please could you help me, as i really need this function for my project and the deadline is approaching; i have asked about emailing number of times before, but was never able to actually implement it.
Email Form Information via Exchange server email send smtp Button Event OnClick e-mail
Thank you,
Faezeh.
Raymond Wen ...
All-Star
32101 Points
3764 Posts
Re: How can I send email from ASP.net to an AOL account automatically using VB language?
Mar 26, 2007 03:02 AM|LINK
In the method's declaration, you should use a argument variable not the value to be passed in.
Public Sub SendMsg(TextBox1.text, "faezeh@aol.com", "yourwebemail@yourdomain.com", feedback.text)
->
public sub SendMsg(byval var1 as string, byval sfrom as string, byval sto as string, byval sfeedback)
Your problems are mainly about the incorrect syntax, I believe visual studio will showdetail information about them and give you more specific ideas of how to correcting them.
Please let me know if there is any problem
faezeh
Member
425 Points
224 Posts
Re: How can I send email from ASP.net to an AOL account automatically using VB language?
Mar 28, 2007 10:48 AM|LINK
does this mean that i should replace the first line with;
public sub SendMsg(byval var1 as string, byval sfrom as string, byval sto as string, byval sfeedback)
if Yes, then where should i put my email address and textbox ID name (email content)?
Thank you,
Faezeh.
docluv
Star
12685 Points
2005 Posts
ASPInsiders
MVP
Re: How can I send email from ASP.net to an AOL account automatically using VB language?
Mar 28, 2007 12:36 PM|LINK