Exemplo n.º 1
0
        public void SendEmailInBackgroundThread(MailContent objMailContent)
        {
            //Thread bgThread = new Thread(new ParameterizedThreadStart(SendAttachment));
            //bgThread.IsBackground = true;
            //bgThread.Start(objMailContent);


            SendAttachment(objMailContent, UserName);

            //SendMailBySendBlue(objMailContent);
        }
Exemplo n.º 2
0
        //public string GetTime(String time)
        //{
        //    string str = Convert.ToDateTime(DateTime.Now).ToShortDateString() + " " + time.Substring(0, 5) + " " + time.Substring(time.Length - 2);
        //    DateTime objDate = Convert.ToDateTime(str);
        //    return objDate.ToString("HH:mm");
        //}

        public void SendEmail(Users emailParameters, List <Attachment> strAttachment = null, AlternateView EventData = null)
        {
            //string xmlData = emailParameters.GetXML();
            // string strBody = !String.IsNullOrEmpty(emailParameters.EmailBody) ? emailParameters.EmailBody : MailerUtility.GetMailBody(HttpContext.Current.Server.MapPath("~") + "\\xslt\\" + emailParameters.XMLFilePath, xmlData);
            //Utilities utilities = new Utilities();
            string strBody = GetMailBody(emailParameters);
            //****************Calling the Send Mail Function *******************************
            MailContent objMailContent = new MailContent()
            {
                From = "*****@*****.**", toEmailaddress = emailParameters.email, displayName = "Vikram Creations Private Limited", subject = emailParameters.Subject, emailBody = strBody, strAttachment = strAttachment, EventData = EventData
            };

            //SendEmailInBackgroundThread(objMailContent);
        }
Exemplo n.º 3
0
        public static void SendAttachment(Object objMail, string UserName)
        {
            MailContent objMailContent = (MailContent)objMail;

            System.Net.Mime.ContentType typeHTML = new System.Net.Mime.ContentType("text/html");
            AlternateView viewHTML = AlternateView.CreateAlternateViewFromString(objMailContent.emailBody, typeHTML);

            viewHTML.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
            //mailMessage.AlternateViews.Add(viewHTML);

            try
            {
                API sendinBlue = new mailinblue.API("sHnhr4w0fTbga7c3"); //add your api key here

                Dictionary <string, Object> data = new Dictionary <string, Object>();
                Dictionary <string, string> to   = new Dictionary <string, string>();
                to.Add(objMailContent.toEmailaddress, "to whom!");

                //to.Add("*****@*****.**", "to whom!");
                List <string> from_name = new List <string>();
                from_name.Add("*****@*****.**");

                //from_name.Add("from email!");
                //List<string> attachment = new List<string>();
                //attachment.Add("https://domain.com/path-to-file/filename1.pdf");
                //attachment.Add("https://domain.com/path-to-file/filename2.jpg");

                data.Add("to", to);
                data.Add("from", from_name);
                data.Add("subject", objMailContent.subject);
                data.Add("html", objMailContent.emailBody);
                //data.Add("attachment", attachment);

                Object sendEmail = sendinBlue.send_email(data);
                string InnerHtml = sendEmail.ToString();

                // Get your account information, plan and credits details
                //GetAccount result = apiInstance.GetAccount();

                //Debug.WriteLine(result);
            }
            catch (Exception ex)
            {
                throw (ex);
            }


            //commented on 12sep2020

            /* MailContent objMC = (MailContent)objMail;
             * if (objMC.toEmailaddress.StartsWith("admin"))
             * {
             *
             * }
             *
             * SmtpClient smtpClient = new SmtpClient();
             * MailMessage mailMessage = new MailMessage();
             *
             *
             *
             * bool flag = false;
             * bool UseSMTPSSL = false;
             * if (!string.IsNullOrEmpty(authenticate))
             * {
             *  flag = Convert.ToBoolean(authenticate);
             * }
             * if (!string.IsNullOrEmpty(UsesmtpSSL))
             * {
             *  UseSMTPSSL = Convert.ToBoolean(UsesmtpSSL);
             * }
             *
             * string host = mailServer;
             *
             * string address = fromEmailID;
             *
             *
             * ////if (UserName != null)
             * //if (objMC.BranchId > 0)
             * //{
             *
             * //    Branch obj = new Branch();
             * //    string email = obj.GetEmailId(objMC.BranchId);
             * //    if (email != "")
             * //    {
             * //        address = email;
             * //    }
             * //}
             *
             * if (!String.IsNullOrEmpty(objMC.From))
             * {
             *  address = objMC.From;
             * }
             *
             * MailAddress from = new MailAddress(address, objMC.displayName);
             *
             * if (objMC.CopyTo.Count > 0)
             * {
             *  foreach (string copyTo in objMC.CopyTo)
             *  {
             *      if (!string.IsNullOrEmpty(copyTo))
             *      {
             *          mailMessage.CC.Add(new MailAddress(copyTo));
             *      }
             *  }
             * }
             *
             *
             * try
             * {
             *
             *  smtpClient.EnableSsl = false;
             *  smtpClient.Host = host;
             *  mailMessage.From = from;
             *  smtpClient.Port = 25;
             *  mailMessage.To.Add(objMC.toEmailaddress);
             *  mailMessage.Subject = objMC.subject;
             *  mailMessage.IsBodyHtml = true;
             *
             *  if (objMC.EventData != null)
             *  {
             *      mailMessage.AlternateViews.Add(objMC.EventData);
             *
             *      System.Net.Mime.ContentType typeHTML = new System.Net.Mime.ContentType("text/html");
             *      AlternateView viewHTML = AlternateView.CreateAlternateViewFromString(objMC.emailBody, typeHTML);
             *      viewHTML.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
             *      mailMessage.AlternateViews.Add(viewHTML);
             *  }
             *  else
             *  {
             *      mailMessage.Body = objMC.emailBody;
             *  }
             *  if (objMC.strAttachment != null)
             *  {
             *      foreach (Attachment a in objMC.strAttachment)
             *      {
             *
             *          mailMessage.Attachments.Add(a);
             *
             *      }
             *  }
             *  if (flag)
             *  {
             *      NetworkCredential credentials = new NetworkCredential(userId, password);
             *      smtpClient.UseDefaultCredentials = false;
             *      smtpClient.Credentials = credentials;
             *  }
             *  else
             *  {
             *      smtpClient.UseDefaultCredentials = true;
             *  }
             *
             *  string sendMail = AllowSendMails;
             *
             *
             *  if (string.IsNullOrEmpty(sendMail) || (sendMail.ToUpper() != "NO"))
             *  {
             *      if (!string.IsNullOrEmpty(objMC.emailBody))
             *      {
             *          smtpClient.Send(mailMessage);
             *          smtpClient.Dispose();
             *      }
             *
             *  }
             *
             *
             *  // update Mail log status of IsDelivered
             *  //MailBoxManager.UpdateDeliveryStatus(MailerLogID, true, "Successfully Send.");
             *
             * }
             * catch (Exception ex)
             * {
             *  //ErrorLogger.Log(ex.Message);
             *  //ErrorLogger.Log(ex.StackTrace);
             *  //update Mail log status of IsDelivered = False and Logtext = ex.mesage
             *  //logger.ErrorFormat(ex.Message);
             *  throw ex;
             * }*/
        }