November 1, 2008

Email sending with attachment

public bool SendEmail(string filename)
{
temp = false;
lstrFrom ="pm8sawant@yahoo.com";
lstrTo = "sawanprasad@gmail.com";
// copy = "y@r.org"+","+"A@gmail.com" ;


System.Net.Mail.MailMessage mymail = new System.Net.Mail.MailMessage(lstrFrom, lstrTo);
mymail.IsBodyHtml = true;
mymail.Subject = "Resume";

StringBuilder MailBody = new StringBuilder();

MailBody.Append(" \n");
MailBody.Append("" + "Comments" + "

\n");
MailBody.Append("" + "Hi Info "+"

\n");
MailBody.Append("" + "This is Resume Of Candidate"+"

\n");

MailBody.Append("");

mymail.Body = MailBody.ToString();

//MailAttachment maAttach = new MailAttachment(filename);
//mymail.Attachments.Add(maAttach);
Attachment at = new Attachment(AppDomain.CurrentDomain.BaseDirectory+ "CV\\"+filename);
mymail.Attachments.Add(at);

// System.Net.Mail.MailMessage mymail = new System.Net.Mail.MailMessage(lstrFrom, lstrTo,"Inquiry", strName);
System.Net.Mail.SmtpClient mySmtp = new System.Net.Mail.SmtpClient();
mySmtp.Host = "localhost";

try
{
mySmtp.Send(mymail);
temp = true;



}
catch (Exception ex)
{
temp = false;

}
return temp;
}

No comments: