i am not able to send email from my application (using c#).
i am getting an exception
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Arun Kumar TiwariPosted Nov 19, 2019, 3:11 AM
Mageshwaran RPosted Nov 19, 2019, 12:04 AM
Shweta DeshmukhPosted Aug 27, 2019, 6:13 AM
Shweta DeshmukhPosted Aug 27, 2019, 6:06 AM
{
try
{
string AppLocation = "";
AppLocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
AppLocation = AppLocation.Replace("file:\\", "");
string file = AppLocation + "\\ExcelFiles\\DataFile.xlsx";
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(ConfigurationManager.AppSettings["Host"].ToString());//smtp.gmail.com
mail.From = new MailAddress(ConfigurationManager.AppSettings["MailFrom"].ToString());//[email protected]
mail.To.Add(MailTo); // Sending MailTo
List
li.Add("[email protected]");
//mail.CC.Add(string.Join
//mail.Bcc.Add(string.Join
mail.Subject = MailSubject; // Mail Subject
//mail.Body = "TwoWaySummary Report *** This is an automatically generated email, please do not reply ***";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(file); //Attaching File to Mail
mail.Attachments.Add(attachment);
// SmtpServer.Port = Convert.ToInt32(ConfigurationManager.AppSettings["PORT"]); //PORT
SmtpServer.Port = 465;//also tried with 587
SmtpServer.EnableSsl = true;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
//SmtpServer.Credentials = new NetworkCredential("Email id of Gmail", "Password of Gmail");
// SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "shweta123");
SmtpServer.Credentials = new NetworkCredential("[email protected]", "Rsl@2005");
// SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "shweta123");
SmtpServer.Send(mail);
}
catch (Exception ex)
{
logger(ex.Message);
logger(ex.StackTrace);
}
finally
{
}
}
Rajeesh MenothPosted Apr 22, 2016, 1:04 AM
Abhishek KumarPosted Apr 21, 2016, 11:17 AM
Rajeesh MenothPosted Apr 17, 2016, 10:08 AM
Amit KumarPosted Apr 16, 2016, 10:55 AM
Abhishek KumarPosted Apr 16, 2016, 10:45 AM
Amit KumarPosted Apr 16, 2016, 9:16 AM
Chandu KumawatPosted Apr 16, 2016, 8:11 AM