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

Source: Internet
Author: User
This is an example of 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: pixel">
</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: pixel ">
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: pixel; 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: pixel; 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.txt from. Text. tostring
Objmail. To = me.txt to. Text. tostring
Objmail. Subject = me.txt subject. Text. tostring
Objmail. Body = me.txt message. 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.