Use System.Web.Mail to send email on the Web

Source: Internet
Author: User
Tags mail tostring visual studio
Web This is an example of a vb.net ~

Email.aspx

<%@ Page language= "VB"
Autoeventwireup= "false"
Codebehind= "Email.aspx.vb"
Inherits= "Asif. SendEmail "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<title>SendEmail</title>
<meta name= "Vs_showgrid" content= "True" >
<meta content= "Microsoft Visual Studio.NET 7.0"
Name= "Generator" >
<meta content= "Visual Basic 7.0" name= "Code_language" >
<meta content= "JavaScript" name= "vs_defaultClientScript" >
<meta content= "Http://schemas.microsoft.com/intellisense/ie5"
Name= "Vs_targetschema" >
</HEAD>
<body ms_positioning= "GridLayout" >
<form id= "Form1" method= "POST" runat= "Server" >
<asp:label id=label5 runat= "Server" width= "464px"
Font-size= "Large" font-bold= "True" forecolor= "Blue"
Style= "Z-INDEX:100; left:140px; Position:absolute;
top:42px ">
Sending Email from ASP.net webpage
</asp:Label>

<asp:textbox id=txtfrom runat= "Server" width= "169px"
Style= "Z-INDEX:101; left:236px; Position:absolute;
Top:104px ">
</asp:TextBox>

<asp:label id=label1 runat= "Server" font-bold= "True"
Font-names= "Arial" font-size= "smaller"
Style= "Z-INDEX:102; left:140px; Position:absolute;
Top:106px ">
From:
</asp:Label>

<asp:requiredfieldvalidator Id=requiredfieldvalidator1
runat= "Server" font-size= "X-small"
Errormessage= "*requiredfield" controltovalidate= "Txtfrom"
Style= "Z-INDEX:103; left:413px; Position:absolute;
top:111px ">
</asp:RequiredFieldValidator>

<asp:textbox id=txtto runat= "Server" width= "168px"
Style= "Z-INDEX:104; left:236px; Position:absolute;
Top:137px ">
</asp:TextBox>

<asp:label id=label2 runat= "Server" font-bold= "True"
Font-names= "Arial" font-size= "smaller"
Style= "Z-INDEX:105; left:140px; Position:absolute;
Top:138px ">
To:
</asp:Label>

<asp:requiredfieldvalidator Id=requiredfieldvalidator4
runat= "Server" font-size= "X-small"
Errormessage= "*requiredfield" controltovalidate= "Txtto"
Style= "Z-INDEX:106; left:417px; Position:absolute;
top:145px ">
</asp:RequiredFieldValidator>

<asp:textbox id=txtsubject runat= "Server" width= "168px"
Style= "Z-INDEX:107; left:236px; Position:absolute;
top:171px ">
</asp:TextBox>

<asp:label id=label4 runat= "Server" font-bold= "True"
Font-names= "Arial" font-size= "smaller"
Style= "Z-INDEX:108; left:140px; Position:absolute;
Top:173px ">
Subject:
</asp:Label>

<asp:requiredfieldvalidator Id=requiredfieldvalidator2
runat= "Server" font-size= "X-small"
Errormessage= "*requiredfield"
Controltovalidate= "Txtsubject" style= "z-index:109;
left:417px; Position:absolute; Top:177px ">
</asp:RequiredFieldValidator>

<asp:textbox id=txtmessage runat= "Server"
Textmode= "MultiLine" width= "349px" height= "188px"
Style= "Z-INDEX:110; left:236px; Position:absolute;
Top:214px ">
</asp:TextBox>

<asp:label id=label3 runat= "Server" font-bold= "True"
Font-names= "Arial" font-size= "smaller"
Style= "z-index:111; left:140px; Position:absolute;
Top:218px ">
Message:
</asp:Label>

<asp:requiredfieldvalidator Id=requiredfieldvalidator3
runat= "Server" font-size= "X-small"
Errormessage= "*requiredfield"
Controltovalidate= "Txtmessage" style= "z-index:112;
left:591px; Position:absolute; top:222px ">
</asp:RequiredFieldValidator>

<asp:button id=cmdsendemail runat= "Server"
text= "Send Email" width= "165px" font-bold= "True"
Style= "z-index:113; left:236px; Position:absolute;
Top:418px ">
</asp:Button>

<asp:label id=lblmessage style= "z-index:114; left:141px;
Position:absolute; TOP:76PX "runat=" Server "
Font-size= "Small" width= "373px" visible= "False" >
</asp:Label>
</form>
</body>
</HTML>


Email.aspx.vb

Imports System.Web.Mail

Public Class SendEmail

Private Sub Cmdsendemail_click (ByVal sender as System.Object, _
ByVal e as System.EventArgs) Handles Cmdsendemail.click

Dim objmail as New mailmessage ()

Objmail.from = Me.txtFrom.Text.ToString
Objmail.to = Me.txtTo.Text.ToString
Objmail.subject = Me.txtSubject.Text.ToString
Objmail.body = Me.txtMessage.Text.ToString
Objmail.bodyformat = mailformat.html
Smtpmail.send (objmail)
Me.lblMessage.Text = "Email has been sent"

End Sub

End Class


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.