Thursday 27 September 2012

Sending Multiple mail in a queue

Sending Multiple mail in a queue in asp.net:

 string strTo = txtTo.Text;
        for (int i = 0; i < strTo.Split(',').Length;i++ )
        {
             string strMailId = strTo.Split(',')[i];
             try
            {
                MailMessage msg = new MailMessage();
                msg.From = txtFrom;
                msg.To=txtTo;
                msg.Subject = txtSubject.Text;
                msg.IsBodyHtml = true;
                msg.Body = txtMail.Text;
                msg.Priority = MailPriority.High;

                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 25);
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential("xxx@gmail.com", "xxx"); //Email and Password

                client.EnableSsl = true;

                client.Send(
msg );
           
                ScriptManager.RegisterStartupScript(btnSend, typeof(Page), "Confirm", "alert('Your enquiry sent successfully!');formReset();", true);
            }
            catch (Exception Ex)
            {
                ScriptManager.RegisterStartupScript(btnSend, typeof(Page), "Error:", "alert('Oops! Some error occoured.')", true);
            }
        }


Monday 3 September 2012

How can I send Email in ASP.Net using C#

How can I send Email in ASP.Net using C#

Answer:
You can use the following code for sending Email:
 MailMessage msg = new MailMessage();
            msg.From = txtFrom.Text);
            msg.To=txtTo,text;
            msg.Subject =txtSubject
            msg.IsBodyHtml = true;
            msg.Body =txtBody.text;
            msg.Priority = MailPriority.High;

            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 25);
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential("xxxxx@gmail.com", "xxxx"); //  Mail Id and it's Password

            client.EnableSsl = true;

            client.Send(msg);

If any suggestion OR any question regarding ASP.Net then drop a mail to mnalammwb@gmail.com


How can I convert a Number to Roman No in asp.Net using c#

How can I convert a Number to Roman No in asp.Net using c#?

Answer:


    static private string Roman(int i)
        {
            return Thounds(i);
        }
        static private string Thounds(int i)
        {
            string strNo = "";
            for (int x = 0; x < i / 1000; x++)
            {
                strNo =strNo+ "M";
            }
            strNo = strNo + UptoThousand(i % 1000);
            return strNo;
        }
        static private string UptoThousand(int i)
        {
            string strNo="";
             for (int x = 0; x < i/100; x++)
                {
                    strNo = strNo + "C";
                }
             if (strNo.Length == 4)
             {
                 strNo = "CD";
             }
             else if (strNo.Length == 5)
             {
                 strNo = "D";
             }
             else if (strNo.Length == 9)
             {
                 string temp  = "CM";
                 strNo = temp;
             }
             else if (strNo.Length >5 && strNo.Length <9)
             {
                 string temp = strNo.Substring(0, 5);
                 temp = "D";
                 strNo = temp + strNo.Substring(5);
             }
             strNo = strNo + UptoHundreds(i%100);
             return strNo;

        }
        static private string UptoHundreds(int i)
        {
            string strNo = "";
            int k = i % 10;
            for (int x = 0; x < i / 10; x++)
                strNo = strNo + "X";
            if (strNo.Length == 4)
            {
                strNo = "IL";
            }
            else if (strNo.Length == 5)
            {
                strNo = "L";
            }
            else  if (strNo.Length == 9)
            {
                string temp = "XC";
                strNo=temp ;
            }
            else if (strNo.Length > 5 && strNo.Length < 9)
            {
                string temp = strNo.Substring(0, 5);
                temp = "L";
                strNo = temp + strNo.Substring(5);
            }
            strNo = strNo + UpToTen(i % 10);
         
            return strNo;
        }      
        static private string UpToTen(int i)
        {

            string strNo = "";
            for (int x = 1; x <= i; x++)
            {
                strNo = strNo + "I";
            }

            if (strNo.Length == 4)
            {
                strNo = "IV";
            }
            else if (strNo.Length == 5)
            {
                strNo = "V";
            }
            else if (strNo.Length == 9)
            {
                string temp = "IX";
                strNo = temp;
            }
            else if (strNo.Length > 5 && strNo.Length < 9)
            {
                string temp = strNo.Substring(0, 5);
                temp = "V";
                strNo = temp + strNo.Substring(5);
            }
            return strNo;
        }
 
If any one to suggest me OR ask me any thing more then mail me to mnalammwb@gmail.com