{"id":30127,"date":"2021-01-18T03:17:22","date_gmt":"2021-01-17T19:17:22","guid":{"rendered":"https:\/\/web.mwwsb.com.my\/pjci\/?post_type=kb&#038;p=30127"},"modified":"2022-09-08T20:17:33","modified_gmt":"2022-09-08T12:17:33","slug":"how-to-send-out-emails-using-asp-script","status":"publish","type":"kb","link":"https:\/\/www.casbay.com\/guide\/kb\/how-to-send-out-emails-using-asp-script","title":{"rendered":"Send out emails using ASP script"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"30127\" class=\"elementor elementor-30127\" data-elementor-post-type=\"kb\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-1db2112 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"1db2112\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a91d174\" data-id=\"a91d174\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-4c1d4ea elementor-widget elementor-widget-heading\" data-id=\"4c1d4ea\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">How to send out emails using ASP script?<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9032c80 elementor-widget elementor-widget-text-editor\" data-id=\"9032c80\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>In Windows 2008, we prefer all users to send out email using CDOSYS mail component. This mail component will integrate into your ASP coding scripts which uses the mail server to send out email instead of CDONTS which is using IIS Virtual SMTP Server.<\/p><p>To send email messages using ASP.NET, your application must:<\/p><ul><li>Create the <strong>SmtpClient<\/strong>\u00a0and\u00a0<strong>MailMessage<\/strong> classes instances.<\/li><li>Set the properties for the\u00a0<strong>SmtpClient<\/strong>\u00a0and\u00a0<strong>MailMessage<\/strong>\u00a0instances (such as the mail server, sender address, recipient address, message subject, and so on).<\/li><li>Call the\u00a0<strong>Send()<\/strong>\u00a0method of the\u00a0<strong>SmtpClient<\/strong>\u00a0instance to send the message.<\/li><\/ul><p>This guide will shows the code samples for C# and VB.NET to demonstrate how to do this, and both are functionally equivalent to each other.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4947224 elementor-widget elementor-widget-heading\" data-id=\"4947224\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">C# example<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3ad76d8 elementor-widget elementor-widget-text-editor\" data-id=\"3ad76d8\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Firstly, create an HTML page that contains a basic interface where the user can specify the message&#8217;s sender, recipient, subject, and body. To do this, copy and paste the following code into a file named <em>mail.aspx<\/em>:<br \/>Secondly, create the code-behind page for the HTML page. To do this, copy and paste the following code into a file named <em>mail.aspx.cs<\/em>. Replace the following text values:<\/p><pre class=\"code\">EventWireup=\"true\" CodeFile=\"mail.aspx.cs\" Inherits=\"SendMail\" %&gt;\n&lt;html&gt;\n&lt;head id=\"Head1\" runat=\"server\"&gt;&lt;title&gt;E-mail test page&lt;\/title&gt;&lt;\/head&gt;\n&lt;body&gt;\n    &lt;form id=\"form1\" runat=\"server\"&gt;\n        Message sender: &lt;asp:textbox id=\"txtFrom\" runat=\"server\" \/&gt;&lt;br&gt;\n        Message recipient: &lt;asp:textbox id=\"txtTo\" runat=\"server\" \/&gt;&lt;br&gt;\n        Message subject: &lt;asp:textbox id=\"txtSubject\" runat=\"server\" \/&gt;&lt;br&gt;\n        Message body:&lt;br\/&gt;\n        &lt;asp:textbox id=\"txtBody\" runat=\"server\" height=\"150px\" textmode=\"multiline\" \/&gt;&lt;br&gt;\n        &lt;asp:button id=\"btn_SendMessage\" runat=\"server\" onclick=\"btn_SendMessage_Click\" text=\"Send message\" \/&gt;&lt;br&gt;\n        &lt;asp:label id=\"Label1\" runat=\"server\" text=\"\" \/&gt;\n    &lt;\/form&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre><p>Secondly, create the code-behind page for the HTML page. To do this, copy and paste the following code into a file named <em>mail.aspx.cs<\/em>. Replace the following text values:<\/p><ul><li style=\"list-style-type: none;\"><ul><li>Replace\u00a0<strong><span class=\"variable\"><em>domain.example.com<\/em><\/span><\/strong>\u00a0with your own domain name.<\/li><li>Replace\u00a0<strong><span class=\"variable\"><em>user@example.com<\/em><\/span><\/strong>\u00a0with the name of an e-mail account you created in Plesk.<\/li><li>Replace\u00a0<strong><span class=\"variable\"><em>password<\/em><\/span>\u00a0<\/strong>with the password for the e-mail account you specified in the previous step.<\/li><\/ul><\/li><\/ul><pre class=\"code\">using System;\nusing System.Web.UI.WebControls;\nusing System.Net.Mail;\n\npublic partial class SendMail : System.Web.UI.Page\n{\n    protected void btn_SendMessage_Click(object sender, EventArgs e)\n    {\n        SmtpClient smtpClient = new SmtpClient(\"<span class=\"variable\"><em>domain.example.com<\/em><\/span>\", 25);\n\n        smtpClient.Credentials = new System.Net.NetworkCredential(\"<span class=\"variable\"><em>user@example.com<\/em><\/span>\", \"<span class=\"variable\"><em>password<\/em><\/span>\");\n        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;\n\n        MailMessage mailMessage = new MailMessage(txtFrom.Text, txtTo.Text);\n        mailMessage.Subject = txtSubject.Text;\n        mailMessage.Body = txtBody.Text;\n\n        try\n        {\n            smtpClient.Send(mailMessage);\n            Label1.Text = \"Message sent\";\n        }\n        catch (Exception ex)\n        {\n            Label1.Text = ex.ToString();\n        }\n    }\n}\n<\/pre><p>Now you can use your web browser to load the\u00a0<em>mail.aspx<\/em>\u00a0file. Complete the fields, click\u00a0<b>Send message<\/b>, and if the values are valid, the server should send the message.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3bb4e0f elementor-widget elementor-widget-heading\" data-id=\"3bb4e0f\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">VB.NET example<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a269eb7 elementor-widget elementor-widget-text-editor\" data-id=\"a269eb7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Firstly, create an HTML page that contains a basic interface where the user can specify the message&#8217;s sender, recipient, subject, and body. To do this, copy and paste the following code into a file named <em>mail.aspx<\/em>:<\/p><pre class=\"code\">&lt;%@ Page Language=\"VB\" AutoEventWireup=\"true\" CodeFile=\"mail.aspx.vb\" Inherits=\"SendMail\" %&gt;\n&lt;html&gt;\n&lt;head id=\"Head1\" runat=\"server\"&gt;&lt;title&gt;E-mail test page&lt;\/title&gt;&lt;\/head&gt;\n&lt;body&gt;\n    &lt;form id=\"form1\" runat=\"server\"&gt;\n        Message sender: &lt;asp:textbox id=\"txtFrom\" runat=\"server\" \/&gt;&lt;br&gt;\n        Message recipient: &lt;asp:textbox id=\"txtTo\" runat=\"server\" \/&gt;&lt;br&gt;\n        Message subject: &lt;asp:textbox id=\"txtSubject\" runat=\"server\" \/&gt;&lt;br&gt;\n        Message body:&lt;br\/&gt;\n        &lt;asp:textbox id=\"txtBody\" runat=\"server\" height=\"150px\" textmode=\"multiline\" \/&gt;&lt;br&gt;\n        &lt;asp:button id=\"btn_SendMessage\" runat=\"server\" onclick=\"btn_SendMessage_Click\" text=\"Send message\" \/&gt;&lt;br&gt;\n        &lt;asp:label id=\"Label1\" runat=\"server\" text=\"\" \/&gt;\n    &lt;\/form&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre><p>Second, create the code-behind page for the HTML page. To do this, copy and paste the following code into a file named\u00a0<em>mail.aspx.vb<\/em>. Replace the following text values:<\/p><ul><li style=\"list-style-type: none;\"><ul><li>Replace\u00a0<strong><span class=\"variable\"><em>domain.example.com<\/em><\/span><\/strong>\u00a0with your own domain name.<\/li><li>Replace\u00a0<strong><span class=\"variable\"><em>user@example.com<\/em><\/span>\u00a0<\/strong>with the name of an e-mail account you created in Plesk.<\/li><li>Replace\u00a0<strong><span class=\"variable\"><em>password<\/em><\/span>\u00a0<\/strong>with the password for the e-mail account you specified in the previous step.<\/li><\/ul><\/li><\/ul><pre class=\"code\">Imports System\nImports System.Web.UI.WebControls\nImports System.Net.Mail\n\nPublic Class SendMail\n    Inherits System.Web.UI.Page\n    \n    Protected Sub btn_SendMessage_Click(ByVal sender As Object, ByVal e As EventArgs)\n\n        Dim smtpClient As SmtpClient = New SmtpClient(\"<span class=\"variable\"><em>domain.example.com<\/em><\/span>\", 25)\n\n        smtpClient.Credentials = New System.Net.NetworkCredential(\"<span class=\"variable\"><em>user@example.com<\/em><\/span>\", \"<span class=\"variable\"><em>password<\/em><\/span>\")\n        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network\n\n        Dim mailMessage As MailMessage = New MailMessage(txtFrom.Text, txtTo.Text)\n        mailMessage.Subject = txtSubject.Text\n        mailMessage.Body = txtBody.Text\n\n        Try \n            smtpClient.Send(mailMessage)\n            Label1.Text = \"Message sent\"\n        Catch ex As Exception\n            Label1.Text = ex.ToString\n        End Try\n\n    End Sub\nEnd Class\n<\/pre><p>Now you can use your web browser to load the\u00a0<em>mail.aspx<\/em>\u00a0file. Complete the fields, click\u00a0<b>Send message<\/b>, and if the values are valid, the server should send the message.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3879610 elementor-widget elementor-widget-text-editor\" data-id=\"3879610\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>We hope this article helped you to learn how to send emails using ASP script. For more articles, please go to <a href=\"https:\/\/www.casbay.com.my\/guide\/\">Knowledge Base<\/a>.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>How to send out emails using ASP script? In Windows 2008, we prefer all users to send out email using CDOSYS mail component. This mail component will integrate into your ASP coding scripts which uses the mail server to send out email instead of CDONTS which is using IIS Virtual SMTP Server. To send email [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"no-sidebar","site-content-layout":"page-builder","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"disabled","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}}},"kbtopic":[49],"kbtag":[106],"mkb_version":[],"_links":{"self":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/30127"}],"collection":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/comments?post=30127"}],"version-history":[{"count":1,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/30127\/revisions"}],"predecessor-version":[{"id":31821,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/30127\/revisions\/31821"}],"wp:attachment":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/media?parent=30127"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kbtopic?post=30127"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kbtag?post=30127"},{"taxonomy":"mkb_version","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/mkb_version?post=30127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}