Esempio n. 1
0
        public string ToXml()
        {
            XmlDocument configXml = new XmlDocument();

            configXml.LoadXml(GetDefaultOrEmptyXml());
            XmlElement root           = configXml.DocumentElement;
            XmlNode    connectionNode = root.SelectSingleNode("smtp");

            connectionNode.SetAttributeValue("hostServer", HostServer);
            connectionNode.SetAttributeValue("useDefaultCredentials", UseDefaultCredentials.ToString());
            connectionNode.SetAttributeValue("domain", Domain);
            connectionNode.SetAttributeValue("userName", UserName);
            connectionNode.SetAttributeValue("password", Password);
            connectionNode.SetAttributeValue("fromAddress", FromAddress);
            connectionNode.SetAttributeValue("toAddress", ToAddress);
            connectionNode.SetAttributeValue("senderAddress", SenderAddress);
            connectionNode.SetAttributeValue("replyToAddress", ReplyToAddress);
            connectionNode.SetAttributeValue("mailPriority", MailPriority);
            connectionNode.SetAttributeValue("isBodyHtml", IsBodyHtml.ToString());
            connectionNode.SetAttributeValue("subject", Subject);
            connectionNode.SetAttributeValue("body", Body);
            connectionNode.SetAttributeValue("useTLS", UseTLS.ToString());
            connectionNode.SetAttributeValue("port", Port.ToString());
            return(configXml.OuterXml);
        }
Esempio n. 2
0
        protected override void Execute(CodeActivityContext context)
        {
            SmtpClient smtpClient = new SmtpClient();

            if (!string.IsNullOrEmpty(SmtpHost.Get(context)))
            {
                smtpClient.Host = SmtpHost.Get(context);
            }
            if (SmtpPort.Get(context).HasValue)
            {
                smtpClient.Port = SmtpPort.Get(context).Value;
            }
            if (!string.IsNullOrEmpty(Username.Get(context)))
            {
                smtpClient.Credentials = new System.Net.NetworkCredential(Username.Get(context), Password.Get(context));
            }
            smtpClient.EnableSsl = EnableSsl.Get(context);

            MailMessage mailMessage = new MailMessage();

            mailMessage.To.Add(To.Get(context));
            mailMessage.From       = new MailAddress(From.Get(context));
            mailMessage.Subject    = Subject.Get(context);
            mailMessage.Body       = Body.Get(context);
            mailMessage.IsBodyHtml = IsBodyHtml.Get(context);

            if (SendAsync.Get(context))
            {
                smtpClient.SendAsync(mailMessage, null);
            }
            else
            {
                smtpClient.Send(mailMessage);
            }
        }
Esempio n. 3
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                MailMessage message = new MailMessage();

                foreach (string emailid in ToEmailAddress.Get(context).Trim().Split(';'))
                {
                    message.To.Add(new MailAddress(emailid));
                }

                if (!string.IsNullOrEmpty(CCEmailAddress.Get(context)))
                {
                    foreach (string emailid in CCEmailAddress.Get(context).Trim().Split(';'))
                    {
                        message.CC.Add(new MailAddress(emailid));
                    }
                }

                if (!string.IsNullOrEmpty(BccEmailAddress.Get(context)))
                {
                    foreach (string emailid in BccEmailAddress.Get(context).Trim().Split(';'))
                    {
                        message.Bcc.Add(new MailAddress(emailid));
                    }
                }


                message.Subject    = Subject.Get(context).Trim();
                message.IsBodyHtml = IsBodyHtml.Get(context); //to make message body as html
                message.Body       = Body.Get(context).Trim();

                Console.WriteLine("----------------------");



                if (MailAttachments.Get(context) != null)
                {
                    Console.WriteLine("Number of Attachments: " + MailAttachments.Get(context).Count.ToString());
                    foreach (string file in MailAttachments.Get(context))
                    {
                        message.Attachments.Add(new Attachment(file));
                    }
                }
                out_MailMessage.Set(context, message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message + "--" + e.Source);
                out_MailMessage.Set(context, null);
            }
        }
Esempio n. 4
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                MailMessage message = new MailMessage();
                SmtpClient  smtp    = new SmtpClient();
                if (string.IsNullOrEmpty(FromEmailAddress.Get(context)))
                {
                    message.From = new MailAddress(SMTP_Email.Get(context));
                }
                else
                {
                    message.From = new MailAddress(FromEmailAddress.Get(context));
                }


                foreach (string emailid in ToEmailAddress.Get(context).Trim().Split(';'))
                {
                    message.To.Add(new MailAddress(emailid));
                }

                if (!string.IsNullOrEmpty(CCEmailAddress.Get(context)))
                {
                    foreach (string emailid in CCEmailAddress.Get(context).Trim().Split(';'))
                    {
                        message.CC.Add(new MailAddress(emailid));
                    }
                }

                if (!string.IsNullOrEmpty(BccEmailAddress.Get(context)))
                {
                    foreach (string emailid in BccEmailAddress.Get(context).Trim().Split(';'))
                    {
                        message.Bcc.Add(new MailAddress(emailid));
                    }
                }


                message.Subject    = Subject.Get(context).Trim();
                message.IsBodyHtml = IsBodyHtml.Get(context); //to make message body as html
                message.Body       = Body.Get(context).Trim();

                Console.WriteLine("----------------------");


                if (MailAttachments.Get(context) != null)
                {
                    Console.WriteLine("Number of Attachments: " + MailAttachments.Get(context).Count.ToString());
                    foreach (string file in MailAttachments.Get(context))
                    {
                        message.Attachments.Add(new Attachment(file));
                    }
                }


                smtp.Port                  = Convert.ToInt32(SMTP_Port.Get(context));
                smtp.Host                  = SMTP_Server.Get(context).Trim();
                smtp.EnableSsl             = EnableSsl.Get(context);
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new System.Net.NetworkCredential(SMTP_Email.Get(context), SMTP_password.Get(context));
                smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                smtp.Send(message);
                IsSuccess.Set(context, true);
                Result.Set(context, string.Empty);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message + "--" + e.Source);
                IsSuccess.Set(context, false);
                Result.Set(context, "Error: " + e.Message);
            }
        }