Sunday, December 11, 2011

How to select max number from substring result of SQL query

Syntax:: select max(convert(int,substring('FeildName',startpos,endpos)))) from tablename

E.g.: select max(convert(int,substring(cardid,3,len(cardid)))) from products

Thursday, March 3, 2011

How to SEND EMAIL IN ASP.NET WITH C# using Gmail


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Mail;

using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;

protected void Button1_Click(object sender, EventArgs e)
{
try
{
SmtpClient mClient = new SmtpClient();
mClient.Port = 587;
mClient.Host = "smtp.gmail.com";
mClient.EnableSsl = true;
mClient.UseDefaultCredentials = false;
mClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
  mClient.Credentials = new System.Net.NetworkCredential("emaiid@gmail.com//your gmail account only", txt_pswd.Text);

MailAddress toAddress = new MailAddress(txt_to.Text);
  MailAddress fromAddress = new MailAddress("email@gmail.com//your gmail account..");
MailMessage MyMail = new MailMessage(fromAddress, toAddress);

MyMail.IsBodyHtml = true;
MyMail.Subject = txt_sub.Text;
MyMail.Body = "" ;
if (FileUpload1.HasFile)
{
Attachment at = new Attachment(FileUpload1.FileContent, System.IO.Path.GetFileName(FileUpload1.FileName));

MyMail.Attachments.Add(at);
}
String mailAddress = txt_to.Text;
string[] emailTo = mailAddress.Split(',');

foreach (string emails in emailTo)
{
if (emails.Trim().Length > 0)
{
MyMail.To.Add(new MailAddress(emails));
}
}

mClient.Send(MyMail);
Response.Write("sent");
}
catch(Exception ee) { Response.Write("Sending Failed"); }

}

Check the snapshot..