Tuesday, April 5, 2011

Sending Email














using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //See "Image.png" attached here to see how the mail looks when received.
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();

            MailAddress fromAddress = new MailAddress("Marketing@Sales.net" , "An Elegant SalesMan" /*Display name, will be displayed in "From" in mailbox*/ );
            // You can specify the host name or ipaddress of your server
            // Default in IIS will be localhost
            smtpClient.Host = "smtp.saha.net";
            //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("rajesh@saha.net");
            message.Subject = "Test Mail";
            // 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 = "rajesh\nchandras\n\n\n\ntest";
        
            // Send SMTP mail
            smtpClient.Send(message);
           
    }
}

No comments:

Post a Comment

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...