Friday 11 May 2012

send mail through smtp server

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Net;
using System.IO;



public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_Click(object sender, EventArgs e)
    {

        try
        {
            if (fu.HasFile)
            {
                string[] ss = fu.FileName.Split('.');
                if (ss[1] == "doc" || ss[1] == "docx")
                {
                    MailMessage ms = new MailMessage();
                    ms.To.Add("anil@swashconvergence.com");
                    ms.Subject = "Mail Send by " + tb.Text;
                    ms.From = new MailAddress("chinmaya@swashconvergence.com");
                    ms.Body = "<html><body><table><tr><td>Name</td><td>:</td><td>" + tb.Text + "</td></tr><tr><td>Location</td><td>:</td><td>" + tb1.Text + "</td></tr><tr><td>Qualification</td><td>:</td><td>" + tb2.Text + "</td></tr><tr><td>Experience Level</td><td>:</td><td>" + tb3.Text + "</td></tr><tr><td>Skills</td><td>:</td><td>" + tb4.Text + "</td></tr><tr><td>Domain Expertise</td><td>:</td><td>" + tb5.Text + "</td></tr><tr><td>Position Applied For</td><td>:</td><td>" + tb6.Text + "</td></tr><tr><td>Email Id</td><td>:</td><td>" + tb7.Text + "</td></tr><tr><td>Mobile Number</td><td>:</td><td>" + tb8.Text + "</td></tr></table></body></html>";
                    ms.CC.Add("chinmaya@swashconvergence.com");
                    ms.Attachments.Add(new Attachment(fu.PostedFile.InputStream, fu.FileName));
                    ms.IsBodyHtml = true;
                    SmtpClient sc = new SmtpClient();
                    sc.Host = "smtp.secureserver.net";
                    sc.Credentials = new System.Net.NetworkCredential("chinmaya@swashconvergence.com", "test@1234");
                    sc.EnableSsl = true;
                    sc.Port = 25;
                    //sc.EnableSsl = true;
                    sc.EnableSsl = false;
                    sc.Send(ms);
                    ClientScript.RegisterClientScriptBlock(GetType(), "yy", "<script>alert('Mail send successfully.')</script>");
                }
                else
                    ClientScript.RegisterClientScriptBlock(GetType(), "yy", "<script>alert('You can  upload noly MSWORD file.')</script>");
            }


        }
        catch (Exception ex)
        {
            ClientScript.RegisterClientScriptBlock(GetType(), "yy", "<script>alert('"+ex.Message+"')</script>");
        }

    }
        
      
       
      
   
}

2 comments:

  1. I am going to give one case against you.SCOTT VONSEL as Administrator From Microsoft.Your most article copied from my site.

    ReplyDelete
  2. Do not take it easy.I have got your address from your blog.Then its easy for me to give a case in police station against you.your all article copied from code project or different Blogs.You have five day in your hand delete your blog or delete all content otherwise you have to penalized to jail and your carrier may be stop.Be serious and delete it as soon as possible.Scott Microsoft Team Member

    ReplyDelete