28 August 2012

Send Email With Template


SmtpClient smtp = new SmtpClient(pSMTP);
                 
                    smtp.Credentials = new NetworkCredential(SendEmail, pPass);
                 
                    //Create the MailMessage object
                    MailMessage msg = new MailMessage();

                    //Assign from address
                    msg.From = new System.Net.Mail.MailAddress(pFromEmail);

                    //Assign to address
                    msg.To.Add(new System.Net.Mail.MailAddress(pTo));
                    if (pCc.Trim() != "")
                    {
                        msg.CC.Add(new System.Net.Mail.MailAddress(pCc));
                    }
                    //smtp.EnableSsl = true;
                    //assign subject, and body
                    msg.Subject = pSubject;
                    msg.Body = pBody;
                    msg.IsBodyHtml = Convert.ToBoolean(pFormat);
                    if (pAttachmentPath.Trim() != "")
                    {
                        msg.Attachments.Add(new System.Net.Mail.Attachment(pAttachmentPath));
                    }
                    //Send the message with SmtpClient
                    smtp.Host = "localhost";
                    smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                    smtp.Send(msg);
                    return true;

20 August 2012

Fine MAC Address in C#


public static PhysicalAddress GetMacAddress()
        {
            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                // Only consider Ethernet network interfaces
                if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
                    nic.OperationalStatus == OperationalStatus.Up)
                {
                    return nic.GetPhysicalAddress();
                }
            }
            return null;
        }