public static void SendMailToCustomer(string email, string pathfile, Mp3Enum mp3) { using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress("*****@*****.**"); mail.To.Add(email); mail.Subject = "Christmas card"; mail.Body = "Dear Sir/Ma'am we wish you a well christmas and a happy new year, in the attachment you will find the christmas card."; mail.IsBodyHtml = true; System.Net.Mail.Attachment attachment; attachment = new System.Net.Mail.Attachment(pathfile); string songfilepath; if (mp3 == Mp3Enum.Jingle1) { var filename = "Andy Williams - It's The Most Wonderful Time Of The Year.mp3"; FileInfo f = new FileInfo(filename); songfilepath = f.FullName; } if (mp3 == Mp3Enum.Jingle2) { var filename = "Mariah Carey - All I Want For Christmas Is You (Official Video).mp3"; FileInfo f = new FileInfo(filename); songfilepath = f.FullName; } else { var filename = "Wham! - Last Christmas (Official Video).mp3"; FileInfo f = new FileInfo(filename); songfilepath = f.FullName; } System.Net.Mail.Attachment songattachment = new Attachment(songfilepath); mail.Attachments.Add(songattachment); mail.Attachments.Add(attachment); using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587)) { smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "testmail"); smtp.EnableSsl = true; smtp.Send(mail); } } }
public static void GenerateAndSendData(ViewModel.SenderAndRecieverFivePersonsSingleChoice model, string contenttext, BackgroundImageEnum background, Mp3Enum song, FontsEnum font) { var stringpath = ITextSharpPdfCreator.GeneratefileForCustomers.GeneratePdfFileForCustomer(ReturnPathString.ReturnUniqueFileName(), model.sender.firstname, model.sender.lastname, contenttext, background, song, font); SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient1.Email, stringpath, song); SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient2.Email, stringpath, song); SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient3.Email, stringpath, song); SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient4.Email, stringpath, song); SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient5.Email, stringpath, song); }
public void GenerateAndSendGeneralChoice(ViewModel.SenderAndRecieverFivePersonsSingleChoice model, string contenttext, BackgroundImageEnum background, Mp3Enum song, FontsEnum font) { var item2 = new GenerateAndSendDataQuintupleDelegate(GeneralFunctions.GeneratePdfAndSendToRecipients.GenerateAndSendData); item.QuintupleGeneralChoiceEvent += item2; item.QuintupleGeneralChoiceEvent(model, contenttext, background, song, font); item.QuintupleGeneralChoiceEvent -= item2; }
public static void GenerateAndSendData(ViewModel.SenderAndRecieversOnePersonSingleChoice model, string contenttext, BackgroundImageEnum background, Mp3Enum song, FontsEnum font) { var stringpath = ITextSharpPdfCreator.GeneratefileForCustomers.GeneratePdfFileForCustomer(ReturnPathString.ReturnUniqueFileName(), model.sender.firstname, model.sender.lastname, contenttext, background, song, font); //<summary> // commented out, to test pdf generation without sending file //<summary> //SmtpMailService.SendCustomerMail.SendMailToCustomer(model.Recipient1.Email,stringpath); }
public static string GeneratePdfFileForCustomer(string filename, string firstname, string lastname, string contenttext, BackgroundImageEnum backgroundimage, Mp3Enum song, FontsEnum font, string addition = "empty") { filename = filename + ".pdf"; Document doc = new Document(iTextSharp.text.PageSize.A4, 0f, 0f, 0f, 0f); PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(filename, FileMode.Create)); //string backgroundfilepath; //if (backgroundimage == BackgroundImageEnum.Background1) //{ // string backgroundfile = "christmas-background1.jpg"; // FileInfo f = new FileInfo(backgroundfile); // backgroundfilepath = f.FullName; //} //if (backgroundimage == BackgroundImageEnum.Background2) //{ // string backgroundfile = "Christmas-background2.jpg"; // FileInfo f = new FileInfo(backgroundfile); // backgroundfilepath = f.FullName; //} //if (backgroundimage == BackgroundImageEnum.Background3) //{ // string backgroundfile = "christmas-background3.jpg"; // FileInfo f = new FileInfo(backgroundfile); // backgroundfilepath = f.FullName; //} doc.Open(); //string storestring1 = "Dear Sir/Ma'am @ thank you heartilly for de purchase at Sjonnie's liquor store @ we will keep you up to date with the latest news"; //string addnewlines1 = storestring1.Replace("@", Environment.NewLine); string storestring1 = "From: @"; storestring1 = storestring1 + "@" + firstname + " " + lastname + "@"; storestring1 = storestring1 + "@" + contenttext; string backgroundfile; if (backgroundimage == BackgroundImageEnum.Background1) { backgroundfile = "christmas-background1.jpg"; } if (backgroundimage == BackgroundImageEnum.Background2) { backgroundfile = "Christmas-background2.jpg"; } else { backgroundfile = "christmas-background3.jpg"; } FileInfo f = new FileInfo(backgroundfile); var backgroundfilepath = f.FullName; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(backgroundfilepath); jpg.SetAbsolutePosition(0, 0); jpg.ScaleAbsolute(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height); jpg.Alignment = iTextSharp.text.Image.UNDERLYING; string addnewlines1 = storestring1.Replace("@", Environment.NewLine); //Paragraph paragraph = new Paragraph(addnewlines1); Paragraph paragraph = new Paragraph(); if (font == FontsEnum.Courier) { paragraph = new Paragraph(addnewlines1, new Font(Font.FontFamily.COURIER, 40)); } if (font == FontsEnum.Helvetica) { paragraph = new Paragraph(addnewlines1, new Font(Font.FontFamily.HELVETICA, 40)); } if (font == FontsEnum.TimesNewRoman) { paragraph = new Paragraph(addnewlines1, new Font(Font.FontFamily.TIMES_ROMAN, 40)); } //paragraph.Alignment = Element.ALIGN_CENTER; paragraph.Alignment = Element.ALIGN_CENTER; paragraph.PaddingTop = Element.ALIGN_MIDDLE; //ColumnText.ShowTextAligned(wri.DirectContent, Element.ALIGN_CENTER, new Phrase("test",), (PageSize.A4.Width/2),(PageSize.A4.Height/2), 0f); ColumnText column = new ColumnText(wri.DirectContent); column.SetSimpleColumn(new Rectangle((PageSize.A4.Width / 2) - 300, 0, PageSize.A4.Width, ((int)Math.Floor(PageSize.A4.Height / 1.5)))); column.AddElement(paragraph); column.Go(); //paragraph.IndentationRight = 100; //paragraph.IndentationLeft = 100; //if (font == FontsEnum.Arial) //{ // paragraph.Font = FontFactory.GetFont("Arial"); //} //else //{ // paragraph.Font = FontFactory.GetFont("Times New Roman"); //} doc.Add(jpg); //doc.Add(paragraph); doc.Close(); var pathpdffile = Path.GetFullPath(filename); return(pathpdffile); }