Send Email (vb code)
Imports System
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Net.Mail
Imports System.Net
Partial Class
Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As
Object,
ByVal e As System.EventArgs)
Handles Me.Load If IsPostBack =
False Then
lblmsg.Visible =
False End
If
End Sub
Protected Sub btnSubmit_Click(ByVal sender As
Object,
ByVal e As System.EventArgs)
Handles btnSubmit.Click Dim name, body, address, Result,
phone, fax, feedback, subject As
String Dim count
As Integer Dim straddress
As Array name = txtName.Text address = txtAdress.Text phone = txtPhone.Text fax = txtFax.Text feedback = txtFeedback.Text subject = txtSubject.text straddress = split(address,
",") For count = 0
To UBound(straddress)
Result += straddress(count) & "<br>" Next body = "<!DOCTYPE HTML
PUBLIC ""-//IETF//DTD HTML//EN"">" body += "<html>" body += "<head>" body += "<title>GRE
Feedback Mail</title>" body += "<meta http-equiv=Content-Type
content=text/html; charset=iso-8859-1>" body += "<style type=text/css>" body += "<!--" body += ".copy {" body += "font-size: 11px;" body += "color: #666666;" body += "font-family: Verdana,
Arial, Helvetica, sans-serif;" body += "}" body += ".body {" body += "font-family: Verdana,
Arial, Helvetica, sans-serif;" body += "font-size: 12px;
font-weight:bold" body += "}" body += "-->" body += "</style>" body += "</head>" body += "<body>" body += "<table width=600
border=0 cellpadding=1 cellspacing=0 border=1>" body += "<tr>" body += "<td><table
border=1 cellspacing=0 cellpadding=5
style=BORDER-RIGHT: #000000 2px solid;BORDER-LEFT: #000000 2px solid;BORDER-BOTTOM:
#000000 2px solid;BORDER-TOP: #000000 2px solid>" body += "<tr>" body += "<td height=1 bgcolor=#000000></td>" body += "</tr>" body += "<tr> " body += "<td bgcolor=#FFFFFF>" body += "<p class=body>" + name + "<br>" body += "" + Result + "<br>" body += "" + phone + "<br>" body += "" + fax + "</p>" 'body += "<p> </p>" 'body += "<p> </p>" body += "<p class=body>Feedback: <br>" body += "<p> " + feedback + "</p>" body += "<p> </p>" body += "<p> </p>" body += "<p> </p>" body += "<p class=copy>©2009
Madras Gauge Room Equipment (P) Limited, " body += "Inc. All Rights Reserved.
</p>" body += "</td>" body += "</tr>" body += "</table></td>" body += "</tr>" body += "</table>" body += "</body>" body +=
"</html>" Response.Write(SendMail("gremachholdings@gmail.com", txtEmail.Text, "info@bloomtechnologies.net", subject, body))
End Sub
Public Function SendMail(ByVal toList As
String,
ByVal fromlist
As
String, ByVal ccList As
String,
ByVal subject
As
String, ByVal body As
String)
As
String Dim message As
New MailMessage() Dim smtpClient
As
New SmtpClient() 'Dim msg As String = String.Empty 'Try Dim fromAddress
As
New MailAddress(fromlist) message.From = fromAddress message.[To].Add(toList) If ccList <>
Nothing AndAlso ccList <>
String.Empty
Then
message.CC.Add(ccList) End
If message.Subject = subject message.IsBodyHtml = True message.Body = body smtpClient.Host = "127.0.0.1" smtpClient.Port = 25 smtpClient.UseDefaultCredentials =
True smtpClient.Credentials = New System.Net.NetworkCredential("webmaster@bloomtechnologies.net", "srihari") smtpClient.Send(message)
' msg =
"Successful" 'Catch ex As Exception ' msg =
ex.Message 'End Try 'Return body lblmsg.Visible = True lblmsg.Text = "Your Feedback
has been sent successfully"
End Function
Protected Sub btnClear_Click(ByVal sender As
Object,
ByVal e As System.EventArgs)
Handles btnClear.Click txtName.Text = "" txtAdress.Text = "" txtEmail.Text = "" txtFax.Text = "" txtFeedback.Text = "" txtPhone.Text
= "" txtSubject.Text = "" lblmsg.Visible = False
End Sub
End Class