private void button7_Click(object sender, EventArgs e)
        {
            Mail mail = new Mail();

            mail.From = txtDe.Text;
            mail.To   = txtPara.Text;
            //mail.Bcc = "*****@*****.**";
            mail.Subject = txtAssunto.Text;
            mail.Body    = txtCorpo.Text;

            //mail.AttachmentList.Add(@"D:\desenvolvimento_old\analise de sistemas\nfe\documentacao\NT_2016_002_v1.51.pdf");

            //KhronusReturn ret = MailUtilities.send("smtp.gmail.com", "*****@*****.**", "fev@030277@", 587, true, mail);
            KhronusReturn ret = MailUtilities.send(txtSmtp.Text, txtUsuario.Text, txtSenha.Text, NumberUtilities.parseInt(txtPorta.Text), chkSsl.Checked, mail);

            MessageBox.Show(ret.Status + " " + ret.Message);
        }
        private void pd_PrintPage2(object sender, PrintPageEventArgs ev)
        {
            float  linesPerPage = 0;
            int    yPos         = 0;
            int    count        = 1;
            int    leftMargin   = 3; // ev.MarginBounds.Left;
            int    topMargin    = 3; // ev.MarginBounds.Top;
            string line         = null;

            //Font printFont = new Font("Lucida Console", 7);
            //printFont = new Font("Letter Gothic Std", 7);
            //Font printFont = new Font("MS Gothic", 8);
            Font printFont = new Font("MS Gothic", 8);

            // Calculate the number of lines per page.
            //linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);

            //Impressao do logo
            //

            //

            //count = 5;

            //yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

            // Print each line of the file.
            while (((line = streamToPrint.ReadLine()) != null))
            {
                //yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

                //RectangleF rect = new RectangleF(leftMargin, yPos, 280f, 100f);

                if (line.StartsWith("{LOGO}"))
                {
                    //Bitmap logo = (Bitmap)Image.FromFile(@"C:\prosis\img\logo-refriauto.png");

                    //ev.Graphics.DrawImage(logo, leftMargin+5, yPos+11, 50, 25);
                }
                else if (line.StartsWith("{128CODE}"))
                {
                    BarcodeLib.Barcode barcode = new BarcodeLib.Barcode();

                    Bitmap bitmap = (Bitmap)barcode.Encode(BarcodeLib.TYPE.CODE128, "35170910292626000172590001709212247548880575", Color.Black, Color.White, 280, 30);

                    ev.Graphics.DrawImage(bitmap, new Rectangle(leftMargin, yPos, 280, 30));
                }
                else if (line.StartsWith("{QRCODE}"))
                {
                    //var bw = new ZXing.BarcodeWriter();
                    //var encOptions = new ZXing.Common.EncodingOptions() { Width = 150, Height = 150, Margin = 0 };
                    //bw.Options = encOptions;
                    //bw.Format = ZXing.BarcodeFormat.QR_CODE;
                    //Bitmap imageQrCode = new Bitmap(bw.Write("https://www.homologacao.nfce.fazenda.sp.gov.br/NFCeConsultaPublica/Paginas/ConsultaQRCode.aspx?chNFe=35160207209613000182650010000000191000000190&nVersao=100&tpAmb=2&dhEmi=323031362d30322d32305431303a33353a35302d30323a3030&vNF=100.00&vICMS=0.00&digVal=55586c7938373833637672394551445570353332776d76336c58303d&cIdToken=000003&cHashQRCode=eebc9c3b9009688a8f668ec5deafd769af7d643b"));

                    //ev.Graphics.DrawImage(imageQrCode, new Rectangle(70, yPos, 150, 150));

                    QRCodeEncoder qrCodecEncoder = new QRCodeEncoder();
                    qrCodecEncoder.QRCodeBackgroundColor = System.Drawing.Color.White;
                    qrCodecEncoder.QRCodeForegroundColor = System.Drawing.Color.Black;
                    //qrCodecEncoder.CharacterSet = "UTF-8";
                    qrCodecEncoder.QRCodeEncodeMode   = QRCodeEncoder.ENCODE_MODE.BYTE;
                    qrCodecEncoder.QRCodeScale        = 6;
                    qrCodecEncoder.QRCodeVersion      = 0;
                    qrCodecEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;

                    Image imageQRCode;
                    //string a ser gerada
                    String dados = "35170910292626000172590001709212247548880575";
                    imageQRCode = qrCodecEncoder.Encode(dados);
                    //picQrCode.Image = imageQRCode;
                    //ev.Graphics.DrawImage(imageQRCode, new Rectangle(leftMargin, yPos, (int)convertCmToPoint(0.5), (int)convertCmToPoint(0.5)));
                    ev.Graphics.DrawImage(imageQRCode, new Rectangle(leftMargin + 80, yPos, 100, 100));
                }
                else
                {
                    //String s0 = StringUtilities.subString(line, 0, 4).Replace("{", "").Replace("}", "");

                    //String n = s0

                    //String s1 = StringUtilities.subString(line, 4);
                    //if (line.StartsWith("{B8}"))
                    //{
                    //    printFont = new Font("MS Gothic", 8, FontStyle.Bold);
                    //}
                    //else
                    //{
                    //   printFont = new Font("MS Gothic", 8, FontStyle.Regular);
                    //}

                    //line = line.Replace("{B}", "");


                    StringFormat format = new StringFormat();

                    if (line.StartsWith("{"))
                    {
                        int pos = line.IndexOf("}");

                        String ini0 = line.Substring(0, pos + 1);

                        String ini1 = ini0.Replace("{", "").Replace("}", "");

                        String[] ini2 = ini1.Split(',');

                        String style = ini2[0];
                        int    size  = NumberUtilities.parseInt(ini2[1]);
                        String align = ini2[2];

                        if (style.Equals("B"))
                        {
                            printFont = new Font("MS Gothic", size, FontStyle.Bold);
                        }
                        else
                        {
                            printFont = new Font("MS Gothic", size, FontStyle.Regular);
                        }

                        StringAlignment a;

                        if (align.Equals("C"))
                        {
                            a = StringAlignment.Center;
                        }
                        else if (align.Equals("L"))
                        {
                            a = StringAlignment.Near;
                        }
                        else
                        {
                            a = StringAlignment.Far;
                        }

                        format.LineAlignment = a;
                        format.Alignment     = a;


                        line = line.Replace(ini0, "");

                        //yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

                        Rectangle rect = new Rectangle(leftMargin, yPos, 280, 12);

                        //ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
                        ev.Graphics.DrawString(line, printFont, Brushes.Black, rect, format);
                    }
                    else
                    {
                        //yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

                        Rectangle rect = new Rectangle(leftMargin, yPos, 280, 12);

                        //ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
                        ev.Graphics.DrawString(line, printFont, Brushes.Black, rect, new StringFormat());
                    }

                    //ev.Graphics.DrawString(
                    //    line,
                    //    printFont,
                    //    Brushes.Black,
                    //    rect,
                    //    new StringFormat());
                }

                count++;

                //yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
                //yPos = rect.Height + (count * printFont.GetHeight(ev.Graphics));

                yPos += 12; // (int)printFont.GetHeight(ev.Graphics);
            }

            //count++;

            //yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));


            //ev.Graphics.DrawString(
            //    "# | COD | DESC | QTD | UN | VL UN R$ | (VL TR R$)*| VL ITEM R$",
            //    printFont,
            //    Brushes.Black,
            //    new RectangleF(leftMargin, yPos, 200f, 100f),
            //    new StringFormat());


            // If more lines exist, print another page.

            /*
             * if (line != null)
             *  ev.HasMorePages = true;
             * else
             *  ev.HasMorePages = false;
             */
        }