דוגמאות קוד לשליחת מכתבים מהקוד של האתר
יש לשלוח אותם דרך ה SMTP שנקרא localhost.
דוגמא לשליחת מכתבים בקוד של ASP קלאסי באמצעות האובייקט JMAIL
dim objMail
set objMail = server.createObject("JMail.Message")
with objMail
.from = "example@evolution.co.il"
.addRecipient "ofir@customerdomain.com", "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("from_example@evolution.co.il", "to_example@evolution.co.il");
// 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("to_example@evolution.co.il");
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("admin1@yoursite.com")
// message.CC.Add("admin1@yoursite.com");
// message.CC.Add("admin2@yoursite.com");
// You can specify Address directly as string
// message.Bcc.Add(new MailAddress("admin3@yoursite.com"));
// message.Bcc.Add(new MailAddress("admin4@yoursite.com"));
//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 ואילך