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. Web. mail;
Namespace baseproject. classes. util
{
Public class mailmanage
{
Public bool Sendmail (string tomail, string subject, string body)
{
Try
{
String frommail = convert. tostring (system. configuration. configurationmanager. receivettings ["mailservice"]? "");
Mailmessage mymail = new mailmessage ();
Mymail. From = frommail;
Mymail. To = tomail;
Mymail. Subject = subject;
Mymail. Body = body;
Mymail. bodyformat = mailformat. html;
//// Attachment
// String serverfilename = "";
// If (this. upfile. postedfile. contentlength! = 0)
//{
// String upfilename = This. upfile. postedfile. filename;
// String [] strtemp = upfilename. Split ('.');
// String upfileexp = strtemp [strtemp. Length-1]. tostring ();
// Serverfilename = server. mappath (datetime. Now. tostring ("yyyymmddhhmmss") + "." + upfileexp );
// This. upfile. postedfile. saveas (serverfilename );
// Mymail. attachments. Add (New mailattachment (serverfilename ));
//}
mymail. fields. add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
mymail. fields. add ("http://schemas.microsoft.com/cdo/configuration/sendusername", convert. tostring (system. configuration. configurationmanager. appsettings ["mailuser"]? ""); // Sender's email account
mymail. fields. add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", convert. tostring (system. configuration. configurationmanager. deleetask[ "mailpass"]? ""); // The sender's email password
Smtpmail. smtpserver = "SMTP." + frommail. substring (frommail. indexof ("@") + 1 );
Smtpmail. Send (mymail );
Return true;
}
Catch
{
Return false;
}
}
}
}