My new blog present here.

Featured Post

Insights into Sitecore Search: A Definitive Introduction

A key component of digital experience management is effective information retrieval. A simplified approach is required for websites, applications, and platforms containing a lot of material so that consumers can easily get the data they require. This need is met by Sitecore, a well-known name in the field of digital experience platforms (DXPs), which provides powerful and comprehensive search functionality. We will travel into the realm of Sitecore Search in this article, learning about its capabilities, architecture , and the enormous value it offers both developers and end users. Introduction to Sitecore Search    A headless content discovery platform powered by AI , Sitecore Search enables you to build predictive and custom search experiences across various content sources. To extract and ...

Send Mail using System.Web.Mail object in C#(C-Sharp):

Send Mail using System.Web.Mail object in C#(C-Sharp):

In Visual Studio 2005 microsoft provided the new mail component called System.Web.Mail for sending email. In this article I am defining you that how can you send the mail in HTML format with attachment.

Add the reference to System.Web.Mail. In this article I am using the function

sendMail for sending email with attachment. The definition of function is

sendMail(string strFrom, string MailID, string strLogFile). In this strFrom variable contains the email address of person who are sending the mail, MailID contains the email addresses of person to whom mail would be send and strLogFile contain the physical path of log file, which send as a attachment. The body part of the function is:

public void sendMail(string strFrom, string MailID, string strLogFile)

{
string strMessage;
string ToMail_ID;
string strYourEmail = strFrom; // from mail id
System.Web.Mail.MailMessage sMail = new MailMessage();
ToMail_ID = MailID; // " LIST OF TO MAIL ID"
sMail.To = ToMail_ID;

sMail.From = strYourEmail;

sMail.BodyFormat = MailFormat.Html;

sMail.Priority = MailPriority.High;

sMail.Attachments.Add(new System.Web.Mail.MailAttachment(strLogFile));

strMessage = "It is test mail.";
sMail.Body = strMessage;

sMail.Subject = “Test Mail”;

SmtpMail.SmtpServer="";

try

{

SmtpMail.Send(sMail);

}

catch (Exception ex)

{

//check the InnerException

while (ex.InnerException != null)

{

ex = ex.InnerException;

}

}

}


Now you can call the function as:
sendMail("mcapassion@gmail.com","mcapassion@gmail.com,a@a.com", "C:\TestMail.log");


Comments

Popular posts from this blog

Sitecore GraphQL Queries

Sitecore Experience Manager Cloud (XM Cloud) Building blocks

Configuring Sitecore Next.js Headless SXA Multisite App in a Sitecore Container