//how to construct for email
        public static bool SendMail(string MessageBody, string Username)
        {
            try
            {
                Microsoft.Office.Interop.Outlook.Application app       = new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook.NameSpace   NS        = app.GetNamespace("MAPI");
                Microsoft.Office.Interop.Outlook.MAPIFolder  objFolder = NS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
                Microsoft.Office.Interop.Outlook.MailItem    objMail   = (Microsoft.Office.Interop.Outlook.MailItem)objFolder.Items.Add(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                //objMail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText;
                objMail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;

                objMail.Body = MessageBody;

                objMail.Subject = "Your Recipe For Day " + DateTime.Now.Date.AddDays(1).ToString("dd/MM/yyyy");
                string email = GetEmailFromDbs(Username, GetConnectionString());
                objMail.To = email;
                objMail.CC = "";
                objMail.Send();

                return(true);
            }
            catch (System.Exception)
            {
                return(false);
            }
        }
        public static void Method2()
        {
            // Create the Outlook application.
            Outlook.Application outlookApp = new Outlook.Application();

            Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

            //Add an attachment.
            String attachmentDisplayName = "MyAttachment";

            // Attach the file to be embedded
            string imageSrc = "D:\\Temp\\test.jpg";     // Change path as needed

            Outlook.Attachment oAttach = mailItem.Attachments.Add(imageSrc, Outlook.OlAttachmentType.olByValue, null, attachmentDisplayName);

            mailItem.Subject = "Sending an embedded image";

            string imageContentid = "someimage.jpg";     // Content ID can be anything. It is referenced in the HTML body

            oAttach.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageContentid);

            mailItem.HTMLBody = String.Format(
                "<body>Hello,<br><br>This is an example of an embedded image:<br><br><img src=\"cid:{0}\"><br><br>Regards,<br>Tarik</body>",
                imageContentid);

            // Add recipient
            Outlook.Recipient recipient = mailItem.Recipients.Add("*****@*****.**");
            recipient.Resolve();

            // Send.
            mailItem.Send();
        }
Exemple #3
0
        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            Outlook.Application application = new Outlook.Application();
            Outlook.NameSpace   ns          = application.GetNamespace("MAPI");

            try
            {
                //get selected mail item
                Object           selectedObject = application.ActiveExplorer().Selection[1];
                Outlook.MailItem selectedMail   = (Outlook.MailItem)selectedObject;

                //create message
                Outlook.MailItem newMail = application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
                newMail.Recipients.Add(ReadFile());
                newMail.Subject = "SPAM";
                newMail.Attachments.Add(selectedMail, Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem);

                newMail.Send();
                selectedMail.Delete();

                System.Windows.Forms.MessageBox.Show("Spam notification has been sent.");
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("You must select a message to report.");
            }
        }
Exemple #4
0
        private void MailButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Outlook.Application _app = new Outlook.Application();
                Outlook.MailItem    mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);

                string filepath = @"D:\Documents\EMPLOYEE PERFORMANCE REVIEW.docx";

                mail.To         = "*****@*****.**";
                mail.Subject    = "Performance Reviews";
                mail.Body       = "benefit enrollments test";
                mail.Importance = Outlook.OlImportance.olImportanceNormal;
                Outlook.Attachment file = mail.Attachments.Add(filepath, Outlook.OlAttachmentType.olByValue, 1, filepath);

                mail.Send();
                MessageBox.Show("message sent");

                _app.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(_app);
            }
            catch
            {
                MessageBox.Show("failed to send email");
            }
        }
        //TODO catch should indicate back to UI that email failed
        public void SendEmailOutlook()
        {
            try
            {
                Outlook.Application app      = new Outlook.Application();
                Outlook.MailItem    mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);
                mailItem.Recipients.Add(Recipients);
                if (SingleAttachment == "")
                {
                    foreach (string item in Attachment)
                    {
                        mailItem.Attachments.Add(item);
                    }
                }
                else
                {
                    mailItem.Attachments.Add(SingleAttachment);
                }

                mailItem.Subject = Subject;
                mailItem.Body    = Body;
                mailItem.Send();
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n" + ex.StackTrace, "Error Sending Email", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #6
0
        public static bool invioEmail(string indirizzo, messaggio messaggio)
        {
            try
            {
                Outlook.Application olkApp1  = new Outlook.Application();
                Outlook.MailItem    olkMail1 = (MailItem)olkApp1.CreateItem(OlItemType.olMailItem);
                Accounts            accounts = olkApp1.Application.Session.Accounts;
                foreach (Account a in accounts)
                {
                    if (a.SmtpAddress == indirizzo)
                    {
                        olkMail1.SendUsingAccount = a;
                    }
                }

                olkMail1.To      = messaggio.Destinatario;
                olkMail1.CC      = messaggio.Copia;
                olkMail1.BCC     = messaggio.CopiaNascosta;
                olkMail1.Subject = messaggio.Oggetto;
                olkMail1.Body    = messaggio.Messaggio;
                if (messaggio.Allegati.Count > 0)
                {
                    messaggio.Allegati.ForEach(delegate(string allegato)
                    {
                        olkMail1.Attachments.Add(allegato);
                    });
                }
                olkMail1.Send();
                return(true);
            }
            catch (System.Exception ex) {
                MailerLogger.SendLogToDB(1, "Errore Durante Invio Messaggi: " + ex.Message);
                return(false);
            }
        }
        private void Sendmail_Click(object sender, RoutedEventArgs e)
        {
            Outlook.Application App = new Outlook.Application();
            Outlook.MailItem    msg = (Outlook.MailItem)App.CreateItem(Outlook.OlItemType.olMailItem);
            msg.HTMLBody = ("<img src=\"" + currentUnit.uris[0] + "\"></img>");
            //msg.HTMLBbody = namehotel;
            msg.Subject = "sujet";
            Outlook.Recipients recips = (Outlook.Recipients)msg.Recipients;
            Outlook.Recipient  recip  = (Outlook.Recipient)recips.Add("*****@*****.**");
            recip.Resolve();
            msg.Send();
            recips = null;
            recip  = null;
            App    = null;
            MessageBox.Show("regarde ton mail");


            //MailMessage mm = new MailMessage();
            //mm.From = new MailAddress("*****@*****.**");
            //mm.To.Add("*****@*****.**");
            //AlternateView htmlView = AlternateView.CreateAlternateViewFromString("https://www.sortiraparis.com/images/80/86252/453698-la-tour-eiffel-fete-ses-130-ans-13.jpg", null, "text/html");

            //LinkedResource image = new LinkedResource(@"C:\Users\bibas\Documents\csharp\imagesprojet\hotelpiscine.jpg");
            //image.ContentId = "monimage";
            //htmlView.LinkedResources.Add(image);
            //mm.AlternateViews.Add(htmlView);
        }
Exemple #8
0
        /// <summary>
        /// Forward the selected email as an attachment
        /// </summary>
        private void SendMailAsAttachment()
        {
            if (!String.IsNullOrEmpty(email))
            {
                Outlook.MailItem selectedMail = GetSelectedItem();
                if (selectedMail != null)
                {
                    var olapp = new Microsoft.Office.Interop.Outlook.Application();

                    Outlook.MailItem mail = olapp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;

                    mail.Subject = "ForwardIt";
                    //Add the configured email.
                    mail.Recipients.Add(email);
                    mail.Attachments.Add(selectedMail, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                    mail.Send();
                }
                else
                {
                    MessageBox.Show("No items selected...");
                }
            }
            else
            {
                MessageBox.Show("Email isn't configured");
            }
        }
Exemple #9
0
        public void sendMailToUser_WhenNOApproverAction(int SRID, string Approver2, string UserMailId)
        {
            try
            {
                Outlook.Application oApp = new Outlook.Application();

                Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

                oMsg.Subject = "Remarks for Ticket ID SR000000" + SRID;

                oMsg.To = UserMailId;

                string sHtml;

                sHtml = "We already tried to take approvals 2 times for this SRID SR000000" + SRID + "." + "<br>" +
                        "However as there is no response from the approvers, the SRID SR000000" + SRID + "will be auto closed." + "<br>" +
                        "We recommend you to raise new SR" + "<br>" +
                        //"Please get in touch with Approver " + Approver2 + "<br>" +
                        " <br>" +
                        "Note: This is automated email and no responses would be monitored";

                oMsg.HTMLBody = sHtml;

                oMsg.Send();

                oMsg = null;

                oApp = null;
            }
            catch (Exception e)
            {
                Log.CreateLog(e);
            }
        }
Exemple #10
0
        static void SendEmail(string subject, string attachment, string recipient, string body)
        {
            var emailTemplate = OutlookSend.Properties.Resource1.emailBody;

            Outlook.Application Application = new Outlook.Application();
            Outlook.MailItem    mail        = Application.CreateItem(
                Outlook.OlItemType.olMailItem) as Outlook.MailItem;
            mail.Subject = subject;
            if (body == "HTML" || body == "html")
            {
                mail.HTMLBody = emailTemplate;
            }
            else
            {
                mail.Body = body;
            }

            Outlook.AddressEntry currentUser =
                Application.Session.CurrentUser.AddressEntry;
            if (currentUser.Type == "EX")
            {
                Console.WriteLine("Sending email to " + recipient);
                mail.Recipients.Add(recipient);
                mail.Recipients.ResolveAll();
                if (attachment != "")
                {
                    mail.Attachments.Add(attachment,
                                         Outlook.OlAttachmentType.olByValue, Type.Missing,
                                         Type.Missing);
                }
                mail.Send();
                Thread.Sleep(2000);
            }
        }
        public void SaveMail()
        {
            Save();

            string Attachmentfilename = $"{Properties.Settings.Default.BestelbonsPath}\\{BestelbonNaam}.pdf";

            Outlook.Application OutlookApplication = new Outlook.Application();
            Outlook.Folder      calFolder          =
                OutlookApplication.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as
                Outlook.Folder;
            Outlook.MailItem mailItem =
                (Outlook.MailItem)OutlookApplication.CreateItem(Outlook.OlItemType.olMailItem);
            mailItem.Subject = $"Bestelbon Project {ProjectNumber}";
            mailItem.To      = Leverancier.Email;
            try
            {
                mailItem.Attachments.Add(Attachmentfilename, Outlook.OlAttachmentType.olByValue, 1, Attachmentfilename);
                mailItem.Send();
            }
            catch (Exception e)
            {
                var dialogViewModel = IoC.Get <DialogViewModel>();
                dialogViewModel.Capiton = "Attachment Error";
                dialogViewModel.Message = e.ToString();
                var result = _windowManager.ShowDialog(dialogViewModel);
            }
        }
Exemple #12
0
        private void sendEmailBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var email = (_Email)e.Argument;

            try
            {
                Outlook.Application oApp = new Outlook.Application();
                Outlook.MailItem    oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                oMsg.Body    = email.Body;
                oMsg.Subject = email.Subject;
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                Outlook.Recipient  oRecip  = (Outlook.Recipient)oRecips.Add(email.Recipient);
                oRecip.Resolve();
                oMsg.Send();
                oRecip  = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;
            }
            catch (Exception ex)
            {
                e.Result = ex;
            }

            e.Result = true;
        }
Exemple #13
0
 //When Status of Complaint updated to Solved
 public bool SolvedEmail(string email, int comaplintId)
 {
     try
     {
         //Random ran = new Random();
         //ran.
         // Create the Outlook application.
         Outlook.Application oApp = new Outlook.Application();
         // Create a new mail item.
         Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
         // Set HTMLBody.
         //add the body of the email
         oMsg.HTMLBody = "Dear User, <br> Your Compalint with ComaplintID: " + comaplintId + " has been resolved.<br> Please login and provide the feedback for the same.";
         //Subject line
         oMsg.Subject = "Your Compalint has been Resolved!!";
         // Add a recipient.
         Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
         // Change the recipient in the next line if necessary.
         Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(email);
         oRecip.Resolve();
         // Send.
         oMsg.Send();
         // Clean up.
         oRecip  = null;
         oRecips = null;
         oMsg    = null;
         oApp    = null;
         return(true);
     }//end of try block
     catch (Exception ex)
     {
         return(false);
     }//end of catch
 }
Exemple #14
0
        public void SendEmail()
        {
            Outlook.Application outlook;
            if ((outlook = GetApplication()) == null)
            {
                output.SetBusinessError("Outlook seems to not be installed on this machine. Aborting");
                return;
            }

            outlook.NewMail += new Outlook.ApplicationEvents_11_NewMailEventHandler(MailReceived);
            received         = false;
            Outlook.MailItem mail = (Outlook.MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);

            mail.Display();

            mail.To = outlook.Session.CurrentUser.Address;

            mail.Subject = input["subject"].ToString();

            mail.Body = "This is a test";

            mail.Send();

            while (!received)
            {
                System.Threading.Thread.Sleep(500);
            }
        }
Exemple #15
0
        internal static void SendEmail(string[] emailDestinations, string emailSubject, string filePathToBeAttached, string emailBody)
        {
            Application application = new Application();

            Outlook.MailItem mail = application.CreateItem(
                Outlook.OlItemType.olMailItem) as Outlook.MailItem;
            mail.Subject = emailSubject;
            Outlook.AddressEntry currentUser =
                application.Session.CurrentUser.AddressEntry;
            if (currentUser.Type == "EX")
            {
                foreach (string email in emailDestinations)
                {
                    if (!String.IsNullOrEmpty(email) && !String.IsNullOrWhiteSpace(email))
                    {
                        mail.Recipients.Add(email);
                    }
                }
                mail.Recipients.ResolveAll();
                mail.Attachments.Add(filePathToBeAttached,
                                     Outlook.OlAttachmentType.olByValue, Type.Missing,
                                     Type.Missing);
                mail.Body = emailBody;
                if (mail.Recipients.Count > 0)
                {
                    mail.Send();
                }
            }
        }
Exemple #16
0
        /* Método compartilhado entre os demais, que envia os emails, conforme título, destinatários, corpo de texto e anexos desejados */
        public void SendEmail(string title, string[] recipients, string body, string[] attachments = null)
        {
            Outlook.Application app  = new Outlook.Application();
            Outlook.MailItem    mail = app.CreateItem(Outlook.OlItemType.olMailItem);
            mail.Subject = title;
            Outlook.AddressEntry currentUser = app.Session.CurrentUser.AddressEntry;

            if (currentUser.Type == "EX")
            {
                Outlook.ExchangeUser manager = currentUser.GetExchangeUser().GetExchangeUserManager();

                foreach (var nome in recipients)
                {
                    mail.Recipients.Add(nome);
                }

                mail.Recipients.ResolveAll();
                mail.HTMLBody = body + currentUser.Name.ToString() + "</ body ></ html >";

                if (attachments != null)
                {
                    foreach (var atch in attachments)
                    {
                        mail.Attachments.Add(atch,
                                             Outlook.OlAttachmentType.olByValue, Type.Missing,
                                             Type.Missing);
                    }
                }

                mail.Send();
            }
        }
Exemple #17
0
        /// <summary>
        /// Compose new email with provided data. A new compose dialog from outlook will be opened.
        /// </summary>
        /// <param name="to">To part of the message</param>
        /// <param name="subject">Subject of the message</param>
        /// <param name="message">Message body in xml</param>
        public void Compose(string to, string subject, string message)
        {
            var app = new Outlook.Application();

            Outlook.MailItem mail = null;
            try
            {
                mail = app.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
            }
            catch (Exception)
            {
                throw new OutlookException();
            }
            var i = mail.GetInspector;

            mail.To       = to;
            mail.Subject  = subject;
            mail.HTMLBody = message + mail.HTMLBody;
            try
            {
                mail.Send();
            }
            catch (Exception)
            {
                throw new SendEmailException();
            }
        }
 private void SendViaEmail(string dest, Outlook.MailItem email)
 {
     Outlook.MailItem newMail = Application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
     newMail = email.Forward();
     newMail.Recipients.Add(dest);
     newMail.Send();
 }
Exemple #19
0
 /// <summary>
 /// Code to send a mail by attaching log file using log4net
 /// </summary>
 public void sendEMailThroughOUTLOOK()
 {
     try
     {
         SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false);
         SplashScreenManager.Default.SetWaitFormDescription("Sending aail to administrator...");
         Outlook.Application oApp = new Outlook.Application();
         Outlook.MailItem    oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
         oMsg.HTMLBody = "Hello, Here is the log file!!";
         String             sDisplayName = "OTTOPro Log File";
         int                iPosition    = (int)oMsg.Body.Length + 1;
         int                iAttachType  = (int)Outlook.OlAttachmentType.olByValue;
         string             st           = Environment.ExpandEnvironmentVariables(@"%AppData%");
         Outlook.Attachment oAttach      = oMsg.Attachments.Add(st + "\\OTTOPro.log", iAttachType, iPosition, sDisplayName);
         oMsg.Subject = "OTTOPro Log File";
         Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
         Outlook.Recipient  oRecip  = (Outlook.Recipient)oRecips.Add("*****@*****.**");
         oRecip.Resolve();
         oMsg.Send();
         oRecip  = null;
         oRecips = null;
         oMsg    = null;
         oApp    = null;
         SplashScreenManager.CloseForm(false);
         XtraMessageBox.Show("Log file mail sent to administrator.!");
     }
     catch (Exception ex) {}
 }
Exemple #20
0
        public void SendEmail(string contacts, string subject, string body, bool htmlFormat)
        {
            try
            {
                this.StartOutlook();

                Outlook.Application outlook = new Outlook.Application();
                Outlook.MailItem    message = (Outlook.MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);

                message.To      = contacts;
                message.Subject = subject;

                if (htmlFormat)
                {
                    message.HTMLBody = body;
                }
                else
                {
                    message.Body = body;
                }

                message.Save();
                message.Send();
            }
            catch (System.Exception e)
            {
                Console.WriteLine("{0} Exception caught: ", e);
            }
        }
 public override void SendEmail(string recipient, string cc, string bcc, string subject, string body)
 {
     ol.Application olApp = new ol.Application();
     ol.MailItem    eMail = (ol.MailItem)olApp.CreateItem(ol.OlItemType.olMailItem);
     eMail.To         = recipient;
     eMail.CC         = cc;
     eMail.BCC        = bcc;
     eMail.Subject    = subject;
     eMail.BodyFormat = (body.StartsWith("<html", StringComparison.CurrentCultureIgnoreCase)) ? ol.OlBodyFormat.olFormatHTML : ol.OlBodyFormat.olFormatPlain;
     if (eMail.BodyFormat == ol.OlBodyFormat.olFormatHTML)
     {
         eMail.HTMLBody = body;
     }
     if (eMail.BodyFormat == ol.OlBodyFormat.olFormatPlain)
     {
         eMail.Body = body;
     }
     if (AutoSend)
     {
         eMail.Send();
     }
     else
     {
         eMail.Save();
         eMail.Display(false);
     }
     Marshal.ReleaseComObject(eMail);
     eMail = null;
 }
Exemple #22
0
        public void AssetExpiryMail(string expiryMailID, string mailBody)
        {
            try
            {
                // Create the Outlook application.
                Outlook.Application oApp = new Outlook.Application();
                // Create a new mail item.
                Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                // Set the subject.
                oMsg.Subject = "Asset Expiry Reminder ";

                oMsg.To = expiryMailID;

                string sHtml = "The Asset will expire as per below details" + "<br>" + "<br>" + mailBody +
                               "<br>" +
                               "If you wish to extend Asset Expiration date, kindly update it else asset will be inactive in next 7 days" + "<br>" + "<br>" +
                               "Note: This is automated email and no responses would be monitored";

                oMsg.HTMLBody = sHtml;


                oMsg.Send();


                oMsg = null;


                oApp = null;
            }
            catch (Exception ex)
            {
            }
        }
Exemple #23
0
        public bool sendmail(string mailto, string mailcc, string strSubject, string strbody, string[] tmpAttachFilePath, string msg)
        {
            try
            {
                mail = (Outlook.MailItem)app.CreateItem(Outlook.OlItemType.olMailItem);
                //ns.Logon("ling.xie", "", false, true);
                mail.To = mailto;
                mail.CC = mailcc;

                mail.Subject = strSubject;

                mail.HTMLBody = strbody;

                foreach (var item in tmpAttachFilePath)
                {
                    mail.Attachments.Add(item, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                }

                mail.Send();
                return(true);
                //ns.Logoff();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
Exemple #24
0
 public bool sendEMailThroughOUTLOOK(string email, string otl)
 {
     try
     {
         //Random ran = new Random();
         //ran.
         // Create the Outlook application.
         Outlook.Application oApp = new Outlook.Application();
         // Create a new mail item.
         Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
         // Set HTMLBody.
         //add the body of the email
         oMsg.HTMLBody = "Hello,Your link to change password : "******"\n. This link will expire after 4 minutes.";
         //Subject line
         oMsg.Subject = "Change Password";
         // Add a recipient.
         Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
         // Change the recipient in the next line if necessary.
         Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(email);
         oRecip.Resolve();
         // Send.
         oMsg.Send();
         // Clean up.
         oRecip  = null;
         oRecips = null;
         oMsg    = null;
         oApp    = null;
         return(true);
     }//end of try block
     catch (Exception ex)
     {
         return(false);
     }//end of catch
 }
        //Send Email with password
        public bool SendMailWithOutlook(string subject, string htmlBody, string recipients, MailSendType sendType)
        {
            // create the outlook application.
            Outlook.Application outlookApp = new Outlook.Application();
            if (outlookApp == null)
            {
                return(false);
            }

            // create a new mail item.
            Outlook.MailItem mail = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

            // set html body.
            // add the body of the email
            mail.HTMLBody = htmlBody;
            mail.Subject  = subject;
            mail.To       = recipients;

            if (sendType == MailSendType.SendDirect)
            {
                mail.Send();
            }
            else if (sendType == MailSendType.ShowModal)
            {
                mail.Display(true);
            }
            else if (sendType == MailSendType.ShowModeless)
            {
                mail.Display(false);
            }

            mail       = null;
            outlookApp = null;
            return(true);
        }
Exemple #26
0
        public bool SendeMailItem(MailDetails mail, bool workBegin)
        {
            if (Properties.Settings.Default.Email == "")
            {
                MessageBox.Show("Please add supervisior mail");
                return(false);
            }

            if (Properties.Settings.Default.MailPrompt)
            {
                DialogResult result = MessageBox.Show("Could I send mail with subject " + mail.Subject, "Work Monit", MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return(false);
                }
            }

            Outlook.MailItem mailItem = (Outlook.MailItem)
                                        this.Application.CreateItem(Outlook.OlItemType.olMailItem);
            mailItem.Subject    = mail.Subject;
            mailItem.To         = Properties.Settings.Default.Email;
            mailItem.RTFBody    = mail.Body;
            mailItem.Importance = Outlook.OlImportance.olImportanceLow;

            mailItem.Send();

            if (workBegin)
            {
                Properties.Settings.Default.OnWorkBeginTime = DateTime.Today;
            }

            return(true);
        }
Exemple #27
0
        private void SendMonthlyReminderForServiceDeliveries(EmployeeProfiles shortlistedEmpsHavingServiceDeliveriesThisMonth)
        {
            string str = string.Empty;

            str  = "<HTML><head><style>table, th, td {border: 1px solid black;}</style></head>";
            str += "<table><tr><th>ALIAS</th><th>NAME</th><th>SERVICE ANNIVERSARY</th></tr>";
            foreach (var item in shortlistedEmpsHavingServiceDeliveriesThisMonth.listOfEmployeeProfiles)
            {
                str += "<tr><td>" +
                       item.Alias +
                       "</td><td>" +
                       item.EmpName +
                       "</td><td>" +
                       item.DateOfJoining.ToString("dd-MMMM-yyyy") +
                       "</td></tr>";
            }

            str += "</body></html>";

            Outlook.MailItem mailItem = (Outlook.MailItem)
                                        this.Application.CreateItem(Outlook.OlItemType.olMailItem);

            mailItem.Subject = "MONTHLY SERVICE DELIVERY REMINDER!!!";
            mailItem.To      = Application.Session.CurrentUser.
                               AddressEntry.GetExchangeUser().PrimarySmtpAddress;
            mailItem.HTMLBody = str;

            mailItem.Importance = Outlook.OlImportance.olImportanceHigh;
            mailItem.Send();
        }
Exemple #28
0
        /// <summary>
        /// Method, that creates a Mail Item
        /// </summary>
        private void CreateMailItem()
        {
            //Outlook.MailItem mailItem = (Outlook.MailItem)
            // this.Application.CreateItem(Outlook.OlItemType.olMailItem);
            Outlook.Application app       = new Outlook.Application();
            Outlook.MailItem    mailItem  = (Outlook.MailItem)app.CreateItem(Outlook.OlItemType.olMailItem);
            Outlook.Recipient   recipient = app.Session.CreateRecipient(sender);
            mailItem.Subject = this.subject;
            mailItem.To      = this.to;
            mailItem.CC      = this.cc;
            mailItem.Body    = this.body;

            if (this.filePaths.Count > 0)
            {
                foreach (string fileName in this.filePaths)
                {
                    string absolute_path = Path.Combine(CBZ.AppPath + fileName);
                    mailItem.Attachments.Add(Path.GetFullPath((new Uri(absolute_path)).LocalPath), Outlook.OlAttachmentType.olByValue, 1, fileName.Remove(0, 14));
                }
            }

            mailItem.Importance = Outlook.OlImportance.olImportanceHigh;
            mailItem.Display(false);
            mailItem.Send();
        }
Exemple #29
0
        public void ReportHam(object sender, RibbonControlEventArgs e)
        {
            Outlook.Application outlookApp = this.Application;

            DialogResult result = MessageBox.Show(global::OutlookSPAMReport.AllResources.MessageBoxConfirmReportHam, "Spam Reporter", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.No)
            {
                return;
            }

            IEnumerable <Outlook.MailItem> selectedEmails = GetSelectedEmails();

            try
            {
                Outlook.MailItem hamReportMailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

                string storeID = outlookApp.ActiveExplorer().CurrentFolder.StoreID;
                foreach (Outlook.Account account in outlookApp.Session.Accounts)
                {
                    if (account.DeliveryStore.StoreID == storeID)
                    {
                        hamReportMailItem.SendUsingAccount = account;
                        break;
                    }
                }


                hamReportMailItem.Body    = "Report ham";
                hamReportMailItem.Subject = "Report ham";
                hamReportMailItem.To      = appSettings.Default.HamTo;
                foreach (Outlook.MailItem oneEmail in selectedEmails)
                {
                    hamReportMailItem.Attachments.Add(oneEmail, Outlook.OlAttachmentType.olEmbeddeditem);
                }
                hamReportMailItem.Send();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            foreach (Outlook.MailItem oneEmail in selectedEmails)
            {
                try
                {
                    Outlook.Folder     parentFolder = (Outlook.Folder)oneEmail.Parent;
                    Outlook.Store      itemStore    = parentFolder.Store;
                    Outlook.MAPIFolder inboxFolder  = itemStore.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                    if (parentFolder.FolderPath != inboxFolder.FolderPath)
                    {
                        oneEmail.Move(inboxFolder);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemple #30
0
        public async Task WyslijMailZZapotrzebowaniemAsync(tblZapotrzebowanie zapotrzebowanie, List <string> adresyMailowe)
        {
            zapotrzebowanieMailItem = new ZapotrzebowanieMailItem(zapotrzebowanie, adresyMailowe);

            Outlook.MailItem mail = zapotrzebowanieMailItem.Create();

            await Task.Run(() => mail.Send());
        }