Sunday, June 29, 2014

send mail in asp.net with attachment and images

   MailMessage m = new MailMessage();
            SmtpClient sc = new SmtpClient();

            try
            {
                m.From = new MailAddress("from@gmail.com", "Shekhar");
                m.To.Add(new MailAddress("snawale@curologic.com", "Amit"));
                // m.CC.Add(new MailAddress("CC@yahoo.com", "Display name CC"));
                //similarly BCC


                m.Subject = " This is a Test Mail";
                m.IsBodyHtml = true;
                m.Body = "Phone number - 9822647640";




                /* // Send With Attachements.
                FileStream fs = new FileStream("E:\\TestFolder\\test.pdf",
                                   FileMode.Open, FileAccess.Read);
                Attachment a = new Attachment(fs, "test.pdf",
                                   MediaTypeNames.Application.Octet);
                m.Attachments.Add(a);
                 */




                /* // Send html email wiht images in it.
                string str = "<html><body><h1>Picture</h1><br/><img
                                 src=\"cid:image1\"></body></html>";
                AlternateView av =
                             AlternateView.CreateAlternateViewFromString(str,
                             null,MediaTypeNames.Text.Html);
                LinkedResource lr = new LinkedResource("E:\\Photos\\hello.jpg",
                             MediaTypeNames.Image.Jpeg);
                lr.ContentId = "image1";
                av.LinkedResources.Add(lr);
                m.AlternateViews.Add(av);
                 */


                sc.Host = "smtp.gmail.com";
                sc.Port = 587;
                sc.Credentials = new
                System.Net.NetworkCredential("from@gmail.com", "password");
                sc.EnableSsl = true;
                sc.Send(m);


                Response.Write("Email Send sucessfully");
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

code for Send mail in asp.net

 MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            mail.From = new MailAddress("from@gmail.com");
            mail.To.Add("send@curologic.com");
            //mail.To.Add("toaddress2@gmail.com");
            mail.Subject = "Password Recovery ";
            mail.Body += " <html>";
            mail.Body += "<body>";
            mail.Body += "<table>";

            mail.Body += "<tr>";
            mail.Body += "<td>User Name : </td><td> HAi </td>";
            mail.Body += "</tr>";

            mail.Body += "<tr>";
            mail.Body += "<td>Password : </td><td>aaaaaaaaaa</td>";
            mail.Body += "</tr>";

            mail.Body += "</table>";
            mail.Body += "</body>";
            mail.Body += "</html>";

            mail.IsBodyHtml = true;
            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("from@gmail.com", "password");
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);

Friday, June 27, 2014

How to Get Window NT Logged User Name Using ASP.NET



1) System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
string strName = p.Identity.Name;


2) string strName = HttpContext.Current.User.Identity.Name.ToString();


3string strName = Request.ServerVariables["AUTH_USER"]; //Finding with name

string strName = Request.ServerVariables[5]; //Finding with index

set hiddenfield value in jquery

  function BindSessionId(id) {
            $('input[id$=hdfsessionid]').val(id);
        }

Wednesday, June 25, 2014

Get Year Only from date in javascript

var startYear = new Date().getFullYear();

Append in jquery

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#btn1").click(function(){
    $("p").append(" <b>Appended text</b>.");
  });

  $("#btn2").click(function(){
    $("ol").append("<li>Appended item</li>");
  });
});
</script>
</head>

<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ol>
<button id="btn1">Append text</button>
<button id="btn2">Append list items</button>
</body>
</html>

Sunday, June 22, 2014

Remove all commas from string in jquery

 var income = $("#txtincome").val(); //12,000
 income = income.replace(/\,/g, '');//12000