public void sendEmail(string email, string pdfFilename, model.File decryptedFile) { string to = email; string from = "*****@*****.**"; string pwd = "Password693"; //smtp SmtpClient client = new SmtpClient(); client.Port = 587; //TLS client.Host = "smtp.gmail.com"; //smtp.gmail.com client.EnableSsl = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(from, pwd); MailMessage message = new MailMessage(); message.From = new MailAddress(from); message.To.Add(to); message.Subject = "Successfull decryption"; message.Body = @"L'application à decrypté un fichier avec un taux de confiance acceptable."; Attachment pdf = new Attachment(pdfFilename); message.Attachments.Add(pdf); try { if (File.Exists(decryptedFile.name)) { File.Delete(decryptedFile.name); } using (FileStream fs = File.Create(decryptedFile.name)) { // Add some text to file Byte[] title = new UTF8Encoding(true).GetBytes(decryptedFile.data); fs.Write(title, 0, title.Length); } } catch (Exception Ex) { Console.WriteLine(Ex.ToString()); } Attachment file = new Attachment(decryptedFile.name); message.Attachments.Add(file); try { client.Send(message); Console.WriteLine("successful email"); } catch (Exception ex) { Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString()); } }
public void notify(model.MsgStruct message) { //arret thread //generation pdf string key = (string)message.data[2]; model.File decryptedfile = new model.File(); string[] splitedFile = ((string)message.data[1]).Split(new char[] { '|' }, 2); decryptedfile.name = splitedFile[0]; decryptedfile.data = splitedFile[1]; int validityRate = (int)message.data[3]; notificationBusiness.pdfGenerator pdfGenerator = new notificationBusiness.pdfGenerator(); String pdf = pdfGenerator.generatePdf(key, validityRate, decryptedfile); notificationBusiness.emailSender Email = new notificationBusiness.emailSender(); Email.sendEmail("*****@*****.**", pdf, decryptedfile); }
public String generatePdf(string key, int ValidityRate, model.File decryptedFile) { PdfDocument document = new PdfDocument(); document.Info.Title = "Decryption Report -" + key + " " + decryptedFile.name; PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XFont font = new XFont("Verdana", 20, XFontStyle.Regular); string text = "Fichier : " + decryptedFile.name + " | Clé : " + key + " | Taux de confiance : " + Convert.ToString(ValidityRate); XTextFormatter tf = new XTextFormatter(gfx); tf.DrawString(text, font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.TopLeft); //gfx.DrawString(text, font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height),XStringFormats.Center); //string test = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); string filename = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Desktop\\Decryption Report -" + key + " " + decryptedFile.name + ".pdf"; document.Save(filename); Process.Start(filename); return(filename); }