Error 1
cod :
protected void SendEmailWithAttachment(object sender, EventArgs e)
{
SendEmail(txtTo.Text.Trim(), "", "", txtSubject.Text.Trim(), txtBody.Text.Trim(), MailPriority.High, false);
}
private void SendEmail(string toAddress, string ccAddress, string bccAddress, string subject, string body, MailPriority priority, bool isHtml)
{
try
{
using (SmtpClient smtpClient = new SmtpClient())
{
using (MailMessage message = new MailMessage())
{
MailAddress fromAddress = new MailAddress("ramji.kid@gmail.com", "ramji.kid, gmail.Com");
// You can specify the host name or ipaddress of your server
smtpClient.Host = "smtp.gmail.com"; //you can also specify mail server IP address here
//Default port will be 25
smtpClient.Port = 25;
NetworkCredential info = new NetworkCredential("ramji.kid@gmail.com", "r");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = info;
//From address will be given as a MailAddress Object
message.From = fromAddress;
message.Priority = priority;
// To address collection of MailAddress
message.To.Add(txt_receiver.Text);
message.Subject = txt_subject.Text;
if (ccAddress.Length > 0)
{
message.CC.Add(ccAddress);
}
if (bccAddress.Length > 0)
{
message.Bcc.Add(bccAddress);
}
//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = isHtml;
// Message body content
message.Body = txt_body.Text;
// Add the attachment, if any
if (FileUpload1.PostedFile.ContentLength > 0)
{
Attachment attachment = new Attachment(Path.GetFullPath(FileUpload1.PostedFile.FileName));
message.Attachments.Add(attachment);
}
// Send SMTP mail
smtpClient.Send(message);
lblMessage.Text = "Email sent to " + toAddress + " successfully !";
}
}
}
catch (Exception ee)
{
lblMessage.Text = ee.ToString();
}
}
can u please help me to rectify this error i am waiting for u