ASP.NET Send Email SMTP Authentication |
ASP.NET Send Email SMTP Authentication ตัวอย่างการเขียน Script ASP.NET สำหรับส่งอีเมล์ โดยมีการเรียกใช้ SMTP และทำการ Authentication Account ของ User และ Password
Language Code : VB.NET || C#
Framework : 1,2,3,4
AspNetSendMailSMTPAuthentication.aspx
<%@ Import Namespace="System.Web.Mail"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim myMail As New MailMessage()
myMail.To = "[email protected]"
myMail.From = "[email protected]"
myMail.Subject = "My Subject"
myMail.BodyFormat = MailFormat.Text
myMail.Body = "My Body & Description"
Dim strSMTP,cdoSendUsingPort,cdoBasic,UserName,Password As String
strSMTP = "localhost"
cdoSendUsingPort = 2
cdoBasic = 1
UserName = "weerachai"
Password = "password"
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", strSMTP)
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25)
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort)
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic)
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", UserName)
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password)
SmtpMail.SmtpServer = strSMTP
SmtpMail.Send(myMail)
myMail = Nothing
Me.lblText.Text = "Mail Sending."
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="server"></asp:Label>
</form>
</body>
</html>
Screenshot

IIS SMTP Virtual Server

|