Please I have a working code which send mails correctly only when I execute the application from visual studio, but when I generate the .exe file and install it, I'm not able to recieve the email ! I think it's not problem coming from code, but maybe something else.
a PDF file generated using NReco.Generator and attached to each mail (it's not problem of access because i'm able to send the same files to Box without problem).
What can be the problem ? everything working well in Visual Studio, but not after installing !
This is the code to generate and send file :
void EnvoyerDOCAsync(string path)
{
SmtpClient MyMail = new SmtpClient(ConfigurationManager.AppSettings["server"], Convert.ToInt16(ConfigurationManager.AppSettings["port"]));
MyMsg = new MailMessage();
MyMsg.Priority = MailPriority.High;
MyMsg.From = new MailAddress(ConfigurationManager.AppSettings["mail"], "Sesrvice Mailing");
foreach (Fonction item in fonction.getFonctions())
{
MyMsg.To.Add(new MailAddress(item.FonctionMail, item.FonctionName));
}
MyMsg.Subject = "Hello";
MyMsg.Body = "Bonjour";
MyMsg.SubjectEncoding = Encoding.UTF8;
MyMsg.IsBodyHtml = true;
MyMsg.BodyEncoding = Encoding.UTF8;
MyMail.UseDefaultCredentials = false;
MyMail.Timeout = (60 * 5 * 1000);
NetworkCredential MyCredentials = new NetworkCredential(ConfigurationManager.AppSettings["sso"], ConfigurationManager.AppSettings["pass"]);
MyMail.Credentials = MyCredentials;
if (File.Exists(path))
{
if (path != null)
{
Attachment attachment = new Attachment(path, MediaTypeNames.Application.Octet);
System.Net.Mime.ContentDisposition disposition = attachment.ContentDisposition;
disposition.CreationDate = File.GetCreationTime(path);
disposition.ModificationDate = File.GetLastWriteTime(path);
disposition.ReadDate = File.GetLastAccessTime(path);
disposition.FileName = Path.GetFileName(path);
disposition.Size = new FileInfo(path).Length;
disposition.DispositionType = DispositionTypeNames.Attachment;
MyMsg.Attachments.Add(attachment);
MyMail.SendAsync(MyMsg, null);
MyMail.SendCompleted += MyMail_SendCompleted;
}
}
}
//Execute this after mail is sended to dispose the Msg and show validation message.<br/>
private void MyMail_SendCompleted(object sender, AsyncCompletedEventArgs e)
{
MyMsg.Dispose();
MessageBox.Show("The mail was sended succesfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Thank you.