I want to send an e-mail with an attachment. This is my code:
try{
OpenFileDialog dlgs = new OpenFileDialog();
if (dlgs.ShowDialog() == DialogResult.OK)
{
string path = dlgs.FileName.ToString();
label10.Text = path;
}
MailMessage mail = new MailMessage("rajithaprasad3@gmail.com","rajithaprasad3@gmail.com","no","no");
mail.Attachments.Add(new Attachment(label10.Text));
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port=587;
client.EnableSsl = true;
client.Send(mail);
MessageBox.Show("Succcessfully Send Your Backup.Please check Mail Inbox", "done", MessageBoxButtons.OK, MessageBoxIcon.Question);
}
catch (Exception ex){
MessageBox.Show(ex.ToString());
MessageBox.Show("This mail Cant Be Sent Make sure You are connected to the internet\n or check whether the particular file stil exite in the system.make sure provided informations are correct", "Eror", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
But when I run the application, it throws an exception message like this
How can I fix it?