コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }