ASP Send Mail Sample
Posted by on 21 August 2012 10:08 PM
|
|
While there are third-party components available to send e-mails from your ASP Web site, the Microsoft® Windows® operating system already includes everything you need to send e-mails from your ASP Web site. The following sample demonstrates how to utilize the built-in components. For further technical details, follow the links provided in the sample.
' In order to run this sample,
' Specifies the method used to send messages. ' Specifies the authentication mechanism to use when authentication is required to send messages to an SMTP service using a TCP/IP network socket. ' The name (DNS) or IP address of the machine hosting the SMTP service through which messages are to be sent. ' The port on which the SMTP service specified by the smtpserver field is listening for connections.
' The username for authenticating to an SMTP server using basic (clear-text) authentication. ' The password used to authenticate to an SMTP server using basic (clear-text) authentication.
' Set mail TO. ' Set mail SUBJECT. ' Set mail BODY (HTMLBody). ' Set mail BODY (TextBody).
<HTML> This is an update to knowledge base article CDOSYS Sample ASP Script | |
|
<%
set mailer = createobject("cdo.message")
mailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
mailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
mailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
mailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
mailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"
mailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxx" ' changed from actual
mailer.Configuration.Fields.Update
mailer.From = "[email protected]" ' changed from actual
mailer.to = "[email protected]"
mailer.Subject = "New Registration for Public Training"
mailer.HTMLBody = "<H3>This is an HTML message.</H3>"
Mailer.Send
set Mailer = Nothing
%>
<HTML>
<BODY>
E-mail sent on <%= Now() %>.
</BODY>
</HTML>
//using System.Net;
//using System.Net.Mail;
string senderEmail = "myemailaddress";
NetworkCredential mailAuthentication = new NetworkCredential(senderEmail, "myemailloginpassword");
SmtpClient mailClient = new SmtpClient("mail.myhostingaccount", 25);
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
//to user
MailMessage MyMailMessage;
MyMailMessage = new MailMessage(senderEmail, emailadd, subject, msg);
MyMailMessage.IsBodyHtml = false;
mailClient.Send(MyMailMessage);