I am working on a website which uses ASP.NET and C#. It takes user input including email through asp.net and then sends email to that email using C#. Actually it send scheduled report to people. But the email is not being sent.
I have also tried setting usedefaultnetworkcredential=false
but it did not work
internal static bool SendEmailNetMail(string toEmail, string subject, string body, MemoryStream ms, string fileName = "attachment.xlx", bool includeLogo = false)
{
toEmail = toEmail.Replace(";", ",");
toEmail = toEmail + ",saeed.bhatti@ver-sys.com";
var fromAddress = new MailAddress("vinspectreports@ver-sys.net", "Scheduled Reports");
// var toAddress = new MailAddress(toEmail, "Valued Customer");
MailAddressCollection addresses = new MailAddressCollection();
addresses.Add(toEmail);
var smtpClient = new SmtpClient() //;
/* not Moving the Email credentials to web.config file*/
{
Host = "mail.ver-sys.net",
Port = 1025,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential("vinspectreports@ver-sys.net", "password"),
Timeout = 900000
};
smtpClient.UseDefaultCredentials = false;
using (var message = new MailMessage()
{
From = fromAddress,
Subject = subject,
Body = body,
IsBodyHtml = true
})
{
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
message.To.Add(toEmail);
try
{
//Attachment attachment = new Attachment("test.xls");
if (ms != null)
{
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("application/vnd.ms-excel");
System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(ms, ct);
attach.ContentDisposition.FileName = fileName;
message.Attachments.Add(attach);
}
// MessageBox.Show("mail Send");
smtpClient.Send(message);
}
catch (Exception ex)
{
Console.Write(ex.Message);
return false;
}
return true;
}