コード例 #1
0
        private void btnAll_Click(object sender, EventArgs e)
        {
            String pathName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pastelusers.csv");

            sw = new StreamWriter(pathName);
            sw.WriteLine("Building,Acc,Emails");
            allCustomers = new List <CustomerConstruct>();
            foreach (DataRow dr in this.astrodonDataSet.tblBuildings.Rows)
            {
                String abbr = dr["code"].ToString();
                if (!String.IsNullOrEmpty(abbr))
                {
                    GetPastelAccounts(abbr);
                }
            }
            sw.Close();

            MailSender.SendMail("*****@*****.**", "*****@*****.**", "Customer List", "Here it is", false, new String[] { pathName });
        }
コード例 #2
0
        public void SendBulkMails(bool flagQueued = false, bool queued = false)
        {
            String mailQuery = "SELECT msg.id, msg.fromAddress, b.Code, b.DataPath, msg.incBCC, msg.bccAddy, msg.subject, msg.message, msg.billBuilding, msg.billAmount FROM tblMsg AS msg ";

            mailQuery += " INNER JOIN tblBuildings AS b ON msg.buildingID = b.id WHERE (msg.id IN (SELECT DISTINCT msgID FROM tblMsgRecipients WHERE(sentDate IS NULL))) ";
            if (flagQueued)
            {
                mailQuery += " AND msg.queue = '" + queued + "'";
            }
            DataHandler dh     = new DataHandler();
            String      status = String.Empty;
            DataSet     ds     = DataHandler.getData(mailQuery, out status);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int     msgID           = int.Parse(dr["id"].ToString());
                    String  bCode           = dr["Code"].ToString();
                    String  dataPath        = dr["DataPath"].ToString();
                    bool    incBCC          = bool.Parse(dr["incBCC"].ToString());
                    String  fromAddress     = dr["fromAddress"].ToString();
                    String  bccAddy         = dr["bccAddy"].ToString();
                    String  subject         = dr["subject"].ToString();
                    String  message         = dr["message"].ToString();
                    bool    billBuilding    = bool.Parse(dr["billBuilding"].ToString());
                    double  billAmount      = double.Parse(dr["billAmount"].ToString());
                    String  attachmentQuery = "SELECT Name, Data FROM tblMsgData WHERE msgID = " + msgID.ToString();
                    DataSet dsAttachment    = DataHandler.getData(attachmentQuery, out status);
                    Dictionary <String, byte[]> attachments = new Dictionary <string, byte[]>();
                    if (dsAttachment != null && dsAttachment.Tables.Count > 0 && dsAttachment.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow drA in dsAttachment.Tables[0].Rows)
                        {
                            try
                            {
                                if (!attachments.ContainsKey(drA["Name"].ToString()))
                                {
                                    attachments.Add(drA["Name"].ToString(), (byte[])drA["Data"]);
                                }
                            }
                            catch { }
                        }
                    }
                    String  billableCustomersQuery = "SELECT distinct accNo FROM tblMsgRecipients WHERE billCustomer = 'True' and msgID = " + msgID.ToString();
                    String  allRecipientsQuery     = "SELECT id, accNo, recipient FROM tblMsgRecipients WHERE sentDate is null AND msgID = " + msgID.ToString();
                    DataSet billableCustomers      = DataHandler.getData(billableCustomersQuery, out status);
                    DataSet receivers = DataHandler.getData(allRecipientsQuery, out status);
                    Dictionary <String, bool> emails = new Dictionary <string, bool>();
                    if (receivers != null && receivers.Tables.Count > 0 && receivers.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow rrece in receivers.Tables[0].Rows)
                        {
                            try
                            {
                                String   id         = rrece["id"].ToString();
                                String[] emailAddys = rrece["recipient"].ToString().Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                                bool     success    = MailSender.SendMail(fromAddress, emailAddys, subject, message, false, false, false, out status, attachments);
                                String   updQuery   = "UPDATE tblMsgRecipients SET sentDate = '" + DateTime.Now.ToString() + "' WHERE id = " + id;
                                RaiseEvent(String.Join(";", emailAddys) + " - " + status);
                                DataHandler.setData(updQuery, out status);
                                if (status != "")
                                {
                                    RaiseEvent(updQuery + " - " + status);
                                }
                                try { emails.Add(rrece["accNo"].ToString(), success); } catch { }
                            }
                            catch { }
                        }
                        String bulkUpdateQuery = "UPDATE tblMsgRecipients SET sentDate = '" + DateTime.Now.ToString() + "' WHERE msgID = " + msgID.ToString();
                        DataHandler.setData(bulkUpdateQuery, out status);
                        if (status != "")
                        {
                            RaiseEvent(bulkUpdateQuery + " - " + status);
                        }
                    }

                    String updateQuery = "UPDATE tblMsg SET queue = 'False' WHERE id = " + msgID.ToString();
                    DataHandler.setData(updateQuery, out status);
                    message += Environment.NewLine + Environment.NewLine;
                    message += "Send status:" + Environment.NewLine + Environment.NewLine;
                    var builder = new System.Text.StringBuilder();
                    builder.Append(message);
                    foreach (KeyValuePair <String, bool> statuses in emails)
                    {
                        builder.Append(statuses.Key + " = " + statuses.Value.ToString() + Environment.NewLine);
                    }
                    message = builder.ToString();
                    if (incBCC)
                    {
                        MailSender.SendMail(fromAddress, new String[] { bccAddy }, subject, message, false, false, false, out status, attachments);
                    }
                }
            }
        }
コード例 #3
0
        public void SendImmediateLetters()
        {
            DataSet queue = GetQueuedLetters(true);

            if (queue != null && queue.Tables.Count > 0 && queue.Tables[0].Rows.Count > 0)
            {
                RaiseEvent("Mail count = " + queue.Tables[0].Rows.Count.ToString());
                foreach (DataRow qDR in queue.Tables[0].Rows)
                {
                    try
                    {
                        String   id      = qDR["id"].ToString();
                        String[] email1  = qDR["toEmail"].ToString().Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                        String   subject = qDR["subject"].ToString();
                        String   message = qDR["message"].ToString();
                        bool     html    = bool.Parse(qDR["html"].ToString());
                        bool     isPA    = html;
                        html = false;
                        bool     addcc       = bool.Parse(qDR["html"].ToString());
                        bool     readreceipt = bool.Parse(qDR["html"].ToString());
                        String[] attachments = qDR["attachment"].ToString().Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < attachments.Length; i++)
                        {
                            if (attachments[i].Contains("PA Attachments"))
                            {
                                RaiseEvent("Original file name = " + attachments[i], "SendImmediateLetters");
                                attachments[i] = attachments[i].Replace("K:\\Debtors System\\PA Attachments\\", @"K:\\Pastel11\\Debtors System\\PA Attachments\\");
                            }
                        }
                        String[] files       = new string[attachments.Length];
                        String   accNo       = qDR["unitno"].ToString();
                        String   debtorEmail = qDR["fromEmail"].ToString();
                        String   sentDate    = qDR["sentDate"].ToString();
                        String   cc          = qDR["cc"].ToString();
                        String   bcc         = qDR["bcc"].ToString();
                        for (int i = 0; i < attachments.Length; i++)
                        {
                            String attachment = attachments[i];
                            String fileName   = GetLetter(attachment);
                            files[i]       = fileName;
                            attachments[i] = fileName;
                            String actFileTitle = Path.GetFileNameWithoutExtension(fileName);
                            String actFile      = Path.GetFileName(fileName);
                        }

                        if (email1.Length > 0 && String.IsNullOrEmpty(sentDate))
                        {
                            status = String.Empty;
                            if (isPA && MailSender.SendMail(debtorEmail, email1, cc, bcc, subject, message, html, out status, attachments))
                            {
                                if (!String.IsNullOrEmpty(status))
                                {
                                    RaiseEvent(status);
                                }
                                String update1 = "UPDATE tblLetterRun SET sentDate = getDate(), errorMessage = 'Processed & Sent' WHERE id = " + id;
                                DataHandler.setData(update1, out status);
                            }
                            else if (MailSender.SendMail("*****@*****.**", email1, addcc ? debtorEmail : String.Empty, subject, message, html, out status, files))
                            {
                                if (!String.IsNullOrEmpty(status))
                                {
                                    RaiseEvent(status);
                                }
                                String update1 = "UPDATE tblLetterRun SET sentDate = getDate(), errorMessage = 'Processed & Sent' WHERE id = " + id;
                                DataHandler.setData(update1, out status);
                            }
                            else
                            {
                                String update1 = "UPDATE tblLetterRun SET sentDate = getDate(), errorMessage = 'Error: " + status + "' WHERE id = " + id;
                                DataHandler.setData(update1, out status);
                                RaiseEvent(status);
                            }
                        }
                        else
                        {
                            RaiseEvent("Can't send mail", "SendImmediateLetters");
                            String update1 = "UPDATE tblLetterRun SET sentDate = getDate(), errorMessage = 'Error: No email address' WHERE id = " + id;
                            DataHandler.setData(update1, out status);
                        }
                    }
                    catch (Exception ex)
                    {
                        RaiseEvent(ex.Message + " " + ex.StackTrace, "SendImmediateLetters");
                    }
                }
            }
        }
コード例 #4
0
        public void Handle(ProcessMessage message, ulong tag)
        {
            var db   = new HistoryBase();
            var data = JsonConvert.DeserializeObject <OrderData>(message.Attachments[Data.OrderDataFile] as string);

            db.Save(data);

            //Tworzenie pustego dokumentu
            PdfDocument document = new PdfDocument();
            //Opcje, używane w tworzeniu czcionek - inaczej nie działają polskie znaki
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            //tytuł #PODAJ JAKIŚ TYTUŁ
            document.Info.Title = "xxx";
            //Dodaj stronę
            PdfPage page = document.AddPage();
            //Stwórz pisaka, tym się wszystko rysuje
            XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

            //Czcionki, mozesz sobie zmienic, jesli chcesz. Uwaga - na koncu musi byc options bo inaczej pierdoli polskie znaki
            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
            XFont fontLarge  = new XFont("Georgia", 24, XFontStyle.Bold, options);
            XFont fontNormal = new XFont("Georgia", 19, XFontStyle.Regular, options);
            XFont fontSmall  = new XFont("Georgia", 17, XFontStyle.Regular, options);

            // Mięsko, czyli tekst. Niestety automatycznie nie dzieli tego na linie, wiec musisz linia po linii robic i samemu je łamać. Chujowo, ale automatyczne łamanie wymagałoby ODZDZIELNEGO gówna, wiec pierdoliłem to
            //Główne powitanie, wyśrodkowane, duze
            gfx.DrawString("Szanowny Kliencie!", fontLarge, XBrushes.Black, new XRect(0, 32, page.Width, page.Height), XStringFormats.TopCenter);
            //tekts pdfa, mozesz sobie zmienic jak cos, co przerwe jest 24 pixele
            gfx.DrawString("Serdecznie dziękujemy za zakupy w naszym sklepie.", fontNormal, XBrushes.Black, new XRect(32, 80, page.Width, page.Height - 32), XStringFormats.TopLeft);
            gfx.DrawString("Jako firma z wieloletnią tradycją wierzymy, że bedziesz", fontNormal, XBrushes.Black, new XRect(32, 104, page.Width, page.Height - 32), XStringFormats.TopLeft);
            gfx.DrawString("zadowolony z jakości naszych kaczek.", fontNormal, XBrushes.Black, new XRect(32, 128, page.Width, page.Height - 32), XStringFormats.TopLeft);
            gfx.DrawString("Poniżej podana jest lista kaczek, które zakupiłeś:", fontNormal, XBrushes.Black, new XRect(32, 176, page.Width, page.Height - 32), XStringFormats.TopLeft);

            // przykładowe wypisanie produktów, liczbe n wykorzustuje do tego, ze potem dalszy tekts odpowiednio obnizam
            foreach (var product in data.Products)
            {
                gfx.DrawString($"{product.Product}: {product.Quantity}", fontSmall, XBrushes.Black, new XRect(48, 200 + data.Products.IndexOf(product) * 22, page.Width, page.Height - 32), XStringFormats.TopLeft);
            }

            var n = data.Products.Count + 1;

            //reszta tekstu, odpowiednio przesunieta po liscie produktow
            gfx.DrawString("Dziękujemy za zakupy i czekamy na kolejne zamówienie!", fontNormal, XBrushes.Black, new XRect(32, 200 + n * 22 + 24, page.Width, page.Height - 32), XStringFormats.TopLeft);
            gfx.DrawString("Rubber Duck Company", fontNormal, XBrushes.Black, new XRect(32, 200 + n * 22 + 48, page.Width, page.Height - 32), XStringFormats.TopLeft);


            //tu jest caly magiczny watermark, nie chce mi sie tlumaczyc co i jak, najwyzej zmien 100 na wieksza lub mniejsza oraz napis "InDucksWeTrust" na inny
            XFont  watermark     = new XFont("Arial", 100, XFontStyle.Bold);
            String watermarkText = "InDucksWeTrust";
            //nie tykac
            var size = gfx.MeasureString(watermarkText, watermark);

            gfx.TranslateTransform(page.Width / 2, page.Height / 2);
            gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
            gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);
            var format = new XStringFormat();

            format.Alignment     = XStringAlignment.Near;
            format.LineAlignment = XLineAlignment.Near;
            //tu jest kolor argb. takze tez mozesz sobie zmienic
            XBrush brush = new XSolidBrush(XColor.FromArgb(50, 63, 72, 204));

            gfx.DrawString(watermarkText, watermark, brush, new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2), format);

            // tu masz nazwe pliku, DAJ JAKAS FAJNA ALBO PO NUMERZE CZY COS!!!
            string filename = $"zamówienie{data.Number}.pdf";

            // tu jest zapis pliku
            document.Save(filename);
            var emailSener = new MailSender();

            emailSener.Send(data.Email, String.Empty, $"zamówienie numer {data.Number}", new List <Attachment>
            {
                new Attachment(filename)
            });

            ShitHelper.Model.BasicAck(tag, false);
        }
コード例 #5
0
        private void GetMail()
        {
            timer.Enabled = false;
            popMessages   = FetchAllMessages(hostName, port, useSSL, username, password);
            mailMessages  = new List <MailMessage>();
            if (popMessages.Count > 0)
            {
                if (messages == null)
                {
                    messages = new Dictionary <string, EmailConstruct>();
                }
                foreach (Message m in popMessages)
                {
                    try
                    {
                        if (!messages.ContainsKey(m.Headers.MessageId))
                        {
                            if (NewMessageEvent != null)
                            {
                                NewMessageEvent(this, new MessageArgs("Event Fired: MailPopped"));
                            }
                            EmailConstruct e = new EmailConstruct();
                            e.ID = m.Headers.MessageId;
                            MailMessage mm   = m.ToMailMessage();
                            String      body = mm.Body;
                            e.SentFrom = mm.From.Address.Replace("@2way.co.za", "");
                            if (NewMessageEvent != null)
                            {
                                NewMessageEvent(this, new MessageArgs(e.SentFrom));
                            }
                            if (mm.To.Count > 0)
                            {
                                e.SentTo = mm.To.ToList()[0].Address;
                            }
                            e.ReceivedDate = m.Headers.DateSent;
                            e.Subject      = mm.Subject;
                            messages.Add(e.ID, new EmailConstruct());
                            if (e.Subject == "SMS to email")
                            {
                                #region SMS Emails

                                List <String> refs = References();
                                foreach (String reference in refs)
                                {
                                    if (e.Body.Contains(reference))
                                    {
                                        e.Reference = reference;
                                        e.Body      = e.Body.Replace(reference, "");
                                        break;
                                    }
                                }
                                if (NewMessageEvent != null)
                                {
                                    NewMessageEvent(this, new MessageArgs("2"));
                                }
                                e.ForwardDate = new DateTime(1900, 1, 1);
                                e.ForwardedTo = "";
                                e.HandledDate = new DateTime(1900, 1, 1);
                                e.Handled     = false;
                                if (NewMessageEvent != null)
                                {
                                    NewMessageEvent(this, new MessageArgs("Before Save"));
                                }
                                SaveMail(ref e);
                                if (NewMessageEvent != null)
                                {
                                    NewMessageEvent(this, new MessageArgs("After save"));
                                }
                                String buildingQuery = "SELECT distinct u.username, u.email, sms.customer FROM tblSMS AS sms INNER JOIN tblBuildings AS b ON sms.building = b.Code INNER JOIN";
                                buildingQuery += " tblUserBuildings AS ub ON b.id = ub.buildingid INNER JOIN tblUsers AS u ON ub.userid = u.id";
                                buildingQuery += " WHERE (sms.sender = '" + e.SentFrom + "')";
                                String  dsStatus = "";
                                DataSet dsUsers  = DataHandler.getData(buildingQuery, out dsStatus);
                                if (dsUsers != null && dsUsers.Tables.Count > 0 && dsUsers.Tables[0].Rows.Count > 0)
                                {
                                    String        msgfrom = "Astrodon Debtors System";
                                    String        subject = "New Message From - " + dsUsers.Tables[0].Rows[0]["customer"].ToString();
                                    String        message = "A new sms message has been received from the above customer.  Please check the Debtor System for more information.";
                                    List <String> toMails = new List <string>();

                                    foreach (DataRow dr in dsUsers.Tables[0].Rows)
                                    {
                                        String toMail = dr["email"].ToString();
                                        if (!String.IsNullOrEmpty(toMail))
                                        {
                                            toMails.Add(toMail);
                                        }
                                    }

                                    if (MailSender.SendMail(msgfrom, toMails, subject, message, false, null))
                                    {
                                        String sentMsg = String.Format("Message sent to {0}", String.Join(";", toMails.ToArray()));
                                        if (NewMessageEvent != null)
                                        {
                                            NewMessageEvent(this, new MessageArgs(sentMsg + " " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
                                        }
                                    }
                                }

                                #endregion SMS Emails
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show(ex.Message);
                    }
                }
                for (int i = messages.Count; i > 0; i--)
                {
                    DeleteMessageOnServer(hostName, port, useSSL, username, password, i);
                }
            }
            timer.Enabled = true;
        }