예제 #1
0
        private void Reformat()
        {
            //Creating invoice model

            DateTime now  = DateTime.Now;
            string   date = String.Format("{0:MMMMM yyyy}", now);

            //Create Receiver from
            Company company = new Company();

            company.Name     = "Tester";
            company.Email    = "*****@*****.**";
            company.Address1 = "59 Paisley Street";
            company.Address2 = "Footscray, Victoria";
            company.Postcode = "3011";
            company.Country  = "Australia";

            //Create Transaction
            Invoice invoice = new Invoice(now, 14);

            invoice.Company   = company;
            invoice.Sender    = new Sender();
            invoice.InvoiceNo = "Tester";

            //Create Item
            Item item = new Item("Emprevo monthly subscription" + " - " + date, "55", "4");

            invoice.AddItem(item);

            //Saving invoice data to company
            company.InvoiceNo           = invoice.InvoiceNo;
            company.RecentDate          = invoice.InvoiceDate;
            company.RecentActiveWorkers = "55";
            company.RecentTotal         = invoice.Total;
            company.RecentRate          = "4";

            InvoiceBL bl = new InvoiceBL();
            //Upload the content of file to cloud

            GCPAdapter adapter = new GCPAdapter();

            adapter.UploadObject("apiemprevo.appspot.com", "Test" + ".pdf", "application/pdf", bl.CreateInvoiceMemoryStream(invoice));
        }
예제 #2
0
        public void SendMail(string aToEmail, string aName, GCPAdapter aAdapter)
        {
            try {
                //From Address
                string FromAddress     = "*****@*****.**";
                string FromAdressTitle = "Sender";
                //To Address
                string ToAddress     = aToEmail;
                string ToAdressTitle = "Receiver";

                string Subject     = "Tax invoice";
                string BodyContent = "This is a test sending tax invoice..";

                var body = new TextPart("plain")
                {
                    Text = BodyContent
                };
                //Smtp Server
                string SmtpServer = "smtp.gmail.com";
                //Smtp Port Number
                int SmtpPortNumber = 587;

                var mimeMessage = new MimeMessage();
                mimeMessage.From.Add(new MailboxAddress(FromAdressTitle, FromAddress));
                mimeMessage.To.Add(new MailboxAddress(ToAdressTitle, ToAddress));
                mimeMessage.Subject = Subject;

                using (MemoryStream ms = new MemoryStream()) {
                    string bucketName = "apiemprevo.appspot.com";
                    aAdapter.DownloadObject(bucketName, aName, ms);

                    var attachment = new MimePart()
                    {
                        ContentObject           = new ContentObject(ms, ContentEncoding.Default),
                        ContentDisposition      = new ContentDisposition(ContentDisposition.Attachment),
                        ContentTransferEncoding = ContentEncoding.Base64,
                        FileName = "invoice.pdf"
                    };

                    //now create the multipart/mixed container to hold the message text and the
                    //file attachment
                    var multipart = new Multipart("mixed");
                    multipart.Add(body);
                    multipart.Add(attachment);

                    // now set the multipart/mixed as the message body
                    mimeMessage.Body = multipart;

                    using (var client = new SmtpClient()) {
                        client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                        client.Connect(SmtpServer, SmtpPortNumber, false);
                        // Note: only needed if the SMTP server requires authentication
                        // Error 5.5.1 Authentication
                        client.Authenticate(FromAddress, "Ch@mp50955");
                        client.Send(mimeMessage);
                        client.Disconnect(true);
                    }
                }
            }
            catch (Exception ex) {
                throw ex;
            }
        }