Ejemplo n.º 1
0
        /// <summary>
        /// Send email via installed client - uses Simple-MAPI.NET library - https://github.com/PandaWood/Simple-MAPI.NET
        /// </summary>
        public void SendMapi(string exceptionReport)
        {
            var mapi = new SimpleMapi();

            mapi.AddRecipient(_config.EmailReportAddress, null, false);
            _attacher.AttachFiles(new AttachAdapter(mapi));

            mapi.Send(EmailSubject, exceptionReport);
        }
Ejemplo n.º 2
0
        public void btnEmail_Click(object sender, EventArgs e)
        {
            //pocetak attachmenta

            OpenFileDialog af = new OpenFileDialog();

            af.Title  = "Attach File";
            af.Filter = "Any File (*.*)|*.*";

            //comboAttachm.Enabled = true;

            WebClient client = new WebClient();

            client.UseDefaultCredentials = true;

            //dohvati lokalizaciju (sr-Lat-Sr)
            var culture = System.Globalization.CultureInfo.CurrentCulture;

            //putanja do stampe Djora 19.05.21
            //var putanjaPdf = "http://" + LoginForm.ReportServer + "/ReportServer/Pages/ReportViewer.aspx?%2fIzvestaji%2f" + kojiprint + imefajla + "&rs:Command=ClearSession&rs:Format=PDF" + "&database=" + Program.NazivBaze + "&Firma=" + Program.imeFirme + "&slike=" + LoginForm.ReportSlike + "&rs:ParameterLanguage=" + culture.ToString() + ParamZaStampu;
            var putanjaPdf = "http://" + LoginForm.ReportServer + "/ReportServer/Pages/ReportViewer.aspx?%2fIzvestaji%2fprn" + imefajla + "&rs:Command=Render&rs:Format=PDF" + "&database=" + Program.NazivBaze + "&server=" + LoginForm.ImeServera + "&username=sa&password=password&Firma=" + Program.imeFirme + "&slike=" + LoginForm.ReportSlike + ParamZaStampu;

            putanjaPdf = putanjaPdf.Replace("#", "%23").Replace("+", "%2b");//prilagodi specijalne karaktere kod passworda (znak + i # prave probleme)

            WebClient webClient = new WebClient();

            client.Headers.Add("Accept-Language", culture.ToString());   //podesava da se zarezi i tacke kod brojeva vide u zavisnosti od jezika u browseru
            webClient.UseDefaultCredentials = true;
            // webClient.DownloadFile(putanjaPdf, @"d:\myfile1.pdf");

            //stavi pdf u memoriju
            byte[]       bytes = client.DownloadData(putanjaPdf);
            MemoryStream ms    = new MemoryStream(bytes);

            //skini pdf u lokalni folder u kome se nalazi projekat
            using (FileStream file = new FileStream(imefajla + ".pdf", FileMode.Create, System.IO.FileAccess.Write))
            {
                ms.Read(bytes, 0, (int)ms.Length);
                file.Write(bytes, 0, bytes.Length);
                ms.Close();


                //Simple Mapi za slanje maila
                var mapi = new SimpleMapi();
                mapi.AddRecipient(name: cmbEmail.Text, addr: null, cc: false);
                mapi.Attach(filepath: file.Name);     //attachuj pdf
                mapi.Send(subject: "", noteText: ""); // otvori mail client

                //obrisi attachment sa racunara
                file.Dispose();
                File.Delete(@"" + file.Name);
                //Kraj Simple Mapi za slanje maila
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Try send via installed Email client
        /// Uses Simple-MAPI.NET library - https://github.com/PandaWood/Simple-MAPI.NET
        /// </summary>
        public void Send(string report)
        {
            if (_config.EmailReportAddress.IsEmpty())
            {
                _sendEvent.ShowError("EmailReportAddress not set", new ConfigurationErrorsException("EmailReportAddress"));
                return;
            }

            var mapi = new SimpleMapi();

            mapi.AddRecipient(_config.EmailReportAddress, null, false);
            _attacher.AttachFiles(new AttachAdapter(mapi));

            mapi.Send(EmailSubject, report);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Try send via installed Email client
        /// Uses Simple-MAPI.NET library - https://github.com/PandaWood/Simple-MAPI.NET
        /// </summary>
        public void Send(string report)
        {
            if (_config.EmailReportAddress.IsEmpty())
            {
                _sendEvent.ShowError("EmailReportAddress not set", new ConfigurationErrorsException("EmailReportAddress"));
                return;
            }

            var mapi = new SimpleMapi();

            //mapi.Logon(System.IntPtr.Zero);		// this code is strictly correct, but won't work with Outlook 64-bit and is needed in the most common usage

            mapi.AddRecipient(_config.EmailReportAddress, _config.EmailReportAddress, false);
            //_attacher.AttachFiles(new AttachAdapter(mapi));
            mapi.Send(EmailSubject, report);
        }
Ejemplo n.º 5
0
        private void cmdOpenEmail_Click(object sender, RoutedEventArgs e)
        {
            string evoid = "MainWindow:OpenEmail_Click";

            try
            {
                string toaddress   = Properties.Settings.Default.EmailTo.ToString();
                string fromaddress = Properties.Settings.Default.EmailFrom.ToString();
                string subject     = Properties.Settings.Default.EmailSubject.ToString();
                if (txtDestinationFolder.Text.Substring(txtDestinationFolder.Text.Length - 1, 1) == "\\")
                {
                    txtDestinationFolder.Text = txtDestinationFolder.Text.Substring(0, txtDestinationFolder.Text.Length - 1);
                }
                string foldername = txtDestinationFolder.Text;
                if (txtSaveFileFormat.Text != null && txtSaveFileFormat.Text != "")
                {
                    foldername += "\\" + txtSaveFileFormat.Text;
                }

                var mapi = new SimpleMapi();
                if (toaddress != "")
                {
                    mapi.AddRecipient(name: toaddress, addr: null, cc: false);
                }
                if (fromaddress != "")
                {
                    mapi.SetSender(fromaddress, senderAddress: null);
                }
                foreach (string s in Directory.GetFiles(foldername))
                {
                    mapi.Attach(s);
                }
                mapi.Send(subject, "Please see the attached photos.", true);
            }
            catch (Exception ex)
            {
                File.WriteAllText(Directory.GetCurrentDirectory() + "\\PhotoEdit_Error.log", "(" + DateTime.Now.ToString() + ") " + evoid + ": " + ex.Message.ToString() + Environment.NewLine);
                MessageBox.Show("An error has occurred. Please see error log for details.", "Error", MessageBoxButton.OK);
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            if ((args == null) || (args.Length < 3))
            {
                Console.WriteLine("SimpleMAPI Console syntax :\n\tConsole-Demo [email protected] subject text");
                return;
            }

            SimpleMapi ma = new SimpleMapi();

            //!ma.Logon(IntPtr.Zero)		// this code is strictly correct, but won't work with Outlook 64-bit and is needed in the most common usage

            ma.AddRecipient(args[0], null, false);
            if (!ma.Send(args[1], args[2]))
            {
                Console.WriteLine("MAPI SendMail failed! : " + ma.Error());
                return;
            }

            //ma.Logoff();
            Console.WriteLine("SimpleMAPI Console: email sent successfully.");
        }