Send Email in asp.net

add System.Net.Mail; namespace
///*********************************************************************************
    ///
    ///To Send the simple  Email
    ///

    ///
From Email Id
    /// To Email Id
    /// Email Subject
    /// Email Body
    /// Returns bool with Indication
    ///*********************************************************************************
    public bool SendEMail(string FromAddressId, string ToAddressId,
                          string Subject, string MessageBody)
    {
        SmtpClient objSmtpClient = new SmtpClient();
        MailMessage message = new MailMessage();

        try
        {
            MailAddress fromAddress = new MailAddress(FromAddressId);
            objSmtpClient.Host = SmtpServerName;
            objSmtpClient.Port = SmtpServerPortNo;
            message.From = fromAddress;
            message.To.Add(ToAddressId);
            message.Subject = Subject;
            message.IsBodyHtml = true;
            message.Body = MessageBody;
            objSmtpClient.Send(message);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            objSmtpClient = null;
            message = null;
        }
    } // End Of Sendmail Function

Comments

Popular posts from this blog

How to get motherboard serial number, Processor ID, VolumeSerialNumber using C#?

Fiserv Interview Questions.

AngularJs - Simple Example