דוגמאות קוד לשליחת מכתבים מהקוד של האתר
יש לשלוח אותם דרך ה SMTP שנקרא localhost.
דוגמא לשליחת מכתבים בקוד של ASP קלאסי באמצעות האובייקט JMAIL
dim objMail
set objMail = server.createObject("JMail.Message")
with objMail
.from = "[email protected]"
.addRecipient "[email protected]", "customer name"
.subject = "This is the SUBJECT"
.HTMLBody = "This is the email BODY"
.charset = "utf-8"
.Send( "localhost) // System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
// System.Net.Mail.SmtpClient is the alternate class for this in 2.0
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("[email protected]", "[email protected]");
// You can specify the host name or ipaddress of your server
// Default in IIS will be localhost
smtpClient.Host = "localhost";
//Default port will be 25
smtpClient.Port = 25;
//From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddress
message.To.Add("[email protected]");
message.Subject = "Subject of the email";
// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("[email protected]")
// message.CC.Add("[email protected]");
// message.CC.Add("[email protected]");
// You can specify Address directly as string
// message.Bcc.Add(new MailAddress("[email protected]"));
// message.Bcc.Add(new MailAddress("[email protected]"));
//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = false;
// Message body content
message.Body = "body";
// Send SMTP mail
smtpClient.Send(message);
lbl_result.Text = "Email successfully sent.";
} catch (Exception ex)
{ lbl_result.Text = "Send Email Failed." + ex.Message;
}
דוגמא לשליחת מכתבים דרך קוד של ASP.NET מגרסא 2 ואילך