public SentStatus Send(string to, string subject, string message, string[] cc, string[] bcc, byte[] attachment, string attachmentname, string replyto)
        {
            bool   status;
            string responseMesage = string.Empty;

            try
            {
                SendGridMessage msg = new SendGridMessage
                {
                    From             = new EmailAddress(Config.EmailAddress, Config.Name),
                    Subject          = subject,
                    PlainTextContent = message,
                    ReplyTo          = new EmailAddress(replyto)
                };
                msg.AddTo(new EmailAddress(to, "User"));
                foreach (string i in cc)
                {
                    msg.AddBcc(new EmailAddress(i));
                }
                foreach (string i in bcc)
                {
                    msg.AddCc(new EmailAddress(i));
                }
                if (attachment != null)
                {
                    var file = Convert.ToBase64String(attachment);
                    msg.AddAttachment(attachmentname, file);
                }
                Client.SendEmailAsync(msg);
                responseMesage = "SendGrid Send success";
                status         = true;
            }
            catch (Exception e)
            {
                responseMesage = "SendGrid Send Exception" + e.Message + e.StackTrace;
                status         = false;
            }
            var        plainTextBytes = Encoding.UTF8.GetBytes(message);
            string     message64      = Convert.ToBase64String(plainTextBytes);
            SentStatus SentStatus     = new SentStatus
            {
                Status     = status.ToString(),
                To         = to,
                From       = Config.EmailAddress,
                Body       = message64,
                ConId      = Config.Id,
                Result     = responseMesage,
                Recepients = new EmailRecepients
                {
                    To      = to,
                    Cc      = (cc == null) ? "" : string.Join(",", cc),
                    Bcc     = (bcc == null) ? "" : string.Join(",", bcc),
                    Replyto = (replyto == null) ? "" : replyto,
                },
                Subject        = subject,
                AttachmentName = attachmentname
            };

            return(SentStatus);
        }
Example #2
0
 /// <summary>
 /// Initiates a new instance of CommandBase
 /// </summary>
 /// <param name="source">Module which generated the command</param>
 /// <param name="destination">Module to which this command will be sent</param>
 /// <param name="command">Command sent</param>
 /// <param name="param">Param sent</param>
 /// <param name="id">id of the command</param>
 public CommandBase(ModuleClient source, ModuleClient destination, string command, string param, int id)
 {
     this.source       = source;
     this.destination  = destination;
     this.parameters   = param;
     this.id           = id;
     this.sentStatus   = SentStatus.NotSentYet;
     this.sendAttempts = 0;
 }
        public SentStatus Send(string to, string subject, string message, string[] cc, string[] bcc, byte[] attachment, string attachmentname, string replyto)
        {
            SentStatus status = new SentStatus();

            try
            {
                Console.WriteLine("Inside Mail Sending to " + to);
                if (Primary != null)
                {
                    status = Primary.Send(to, subject, message, cc, bcc, attachment, attachmentname, replyto);
                    Console.WriteLine("Mail Send With Primary :");
                }
                else if (this.Capacity != 0)
                {
                    Console.WriteLine("Mail Send using First Element");
                    status = this[0].Send(to, subject, message, cc, bcc, attachment, attachmentname, replyto);
                }
                else
                {
                    Console.WriteLine("Email Connection Empty!");
                }
            }
            catch
            {
                try
                {
                    if (FallBack != null)
                    {
                        status = FallBack.Send(to, subject, message, cc, bcc, attachment, attachmentname, replyto);
                        Console.WriteLine("Mail Send With FallBack : ");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Mail Sending Failed: " + ex.StackTrace);
                }
            }
            return(status);
        }
Example #4
0
 public FeedItem()
 {
     NotificationStatus = SentStatus.NotSent;
 }
Example #5
0
 /// <summary>
 /// Default constructor for further initialization
 /// </summary>
 protected CommandBase()
 {
     this.sentStatus   = SentStatus.NotSentYet;
     this.sendAttempts = 0;
 }
        public SentStatus Send(string to, string subject, string message, string[] cc, string[] bcc, byte[] attachment, string attachmentname, string replyto)
        {
            bool   status;
            string responseMesage = string.Empty;

            try
            {
                MailMessage mm = new MailMessage(Config.EmailAddress, to)
                {
                    Subject    = subject,
                    IsBodyHtml = true,
                    Body       = message,
                };

                if (replyto != null)
                {
                    mm.ReplyToList.Add(replyto);
                }
                if (attachment != null)
                {
                    mm.Attachments.Add(new System.Net.Mail.Attachment(new MemoryStream(attachment), attachmentname));
                }
                if (cc?.Length > 0)
                {
                    foreach (string item in cc)
                    {
                        if (item != "")
                        {
                            mm.CC.Add(item);
                        }
                    }
                }
                if (bcc?.Length > 0)
                {
                    foreach (string item in bcc)
                    {
                        if (item != "")
                        {
                            mm.Bcc.Add(item);
                        }
                    }
                }

                Client.Send(mm);
                status         = true;
                responseMesage = "Smtp Send success";
            }
            catch (Exception e)
            {
                responseMesage = "Smtp Send Exception : Port" + " - " + Config.Port + " :  " + e.Message + e.StackTrace;
                status         = false;
            }
            var        plainTextBytes = System.Text.Encoding.UTF8.GetBytes(message);
            string     message64      = System.Convert.ToBase64String(plainTextBytes);
            SentStatus SentStatus     = new SentStatus
            {
                Status     = status.ToString(),
                To         = to,
                From       = Config.EmailAddress,
                Body       = message64,
                ConId      = Config.Id,
                Result     = responseMesage,
                Recepients = new EmailRecepients
                {
                    To      = to,
                    Cc      = (cc == null) ? "" : string.Join(",", cc),
                    Bcc     = (bcc == null) ? "" : string.Join(",", bcc),
                    Replyto = (replyto == null) ? "" : replyto,
                },
                Subject        = subject,
                AttachmentName = attachmentname
            };

            return(SentStatus);
        }
Example #7
0
 public EmailMessage()
 {
     Created_Date = DateTime.Now.ToFileTimeUtc();
     SentStatus   = SentStatus.New;
 }
Example #8
0
 public SendReturnObject(string message, SentStatus status, int retId)
 {
     Message     = message;
     Status      = status;
     RetrievalId = retId;
 }