Exemple #1
0
        /// <summary>
        /// From this email recipient, extract the SMTP address (if that's possible).
        /// </summary>
        /// <param name="recipient">A recipient object</param>
        /// <returns>The SMTP address for that object, if it can be recovered, else an empty string.</returns>
        public static string GetSmtpAddress(this Outlook.Recipient recipient)
        {
            string result = string.Empty;

            switch (recipient.AddressEntry.Type)
            {
            case "SMTP":
                result = recipient.Address;
                break;

            case "EX":     /* an Exchange address */
                var exchangeUser = recipient.AddressEntry.GetExchangeUser();
                if (exchangeUser != null)
                {
                    result = exchangeUser.PrimarySmtpAddress;
                }
                break;

            default:
                Globals.ThisAddIn.Log.AddEntry(
                    $"RecipientExtensions.GetSmtpAddres: unknown email type {recipient.AddressEntry.Type}",
                    SuiteCRMClient.Logging.LogEntryType.Warning);
                break;
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Get the token used by CRM to reflect the acceptance status of this recipient.
        /// </summary>
        /// <param name="recipient">The recipient.</param>
        /// <returns>The acceptance status.</returns>
        public static string CrmAcceptanceStatus(this Outlook.Recipient recipient)
        {
            string acceptance = string.Empty;

            switch (recipient.MeetingResponseStatus)
            {
            case Outlook.OlResponseStatus.olResponseAccepted:
            case Microsoft.Office.Interop.Outlook.OlResponseStatus.olResponseOrganized:
                acceptance = "accept";
                break;

            case Outlook.OlResponseStatus.olResponseTentative:
                acceptance = "tentative";
                break;

            case Microsoft.Office.Interop.Outlook.OlResponseStatus.olResponseNone:
            case Microsoft.Office.Interop.Outlook.OlResponseStatus.olResponseNotResponded:
                // nothing to do
                break;

            case Outlook.OlResponseStatus.olResponseDeclined:
            default:
                acceptance = "decline";
                break;
            }

            return(acceptance);
        }
Exemple #3
0
        /// <summary>
        /// From this email recipient, extract the SMTP address (if that's possible).
        /// </summary>
        /// <param name="recipient">A recipient object</param>
        /// <returns>The SMTP address for that object, if it can be recovered, else an empty string.</returns>
        private string GetSmtpAddress(Outlook.Recipient recipient)
        {
            string result = string.Empty;

            switch (recipient.AddressEntry.Type)
            {
            case "SMTP":
                result = recipient.Address;
                break;

            case "EX":     /* an Exchange address */
                var exchangeUser = recipient.AddressEntry.GetExchangeUser();
                if (exchangeUser != null)
                {
                    result = exchangeUser.PrimarySmtpAddress;
                }
                break;

            default:
                this.Log.Warn($"{this.GetType().Name}.ExtractSmtpAddressForSender: unknown email type {recipient.AddressEntry.Type}");
                break;
            }

            return(result);
        }
        public static void SendEmailToSupport(Exception catchedException)
        {
            try
            {
                LoginInfo loginInfo = LoginInfo.GetInstance();

                Outlook.Application outlookApp = GetApplicationObject();
                Outlook._MailItem   mailItem   = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                mailItem.Subject = loginInfo.UserName + "---ERROR: " + catchedException.Message;
                mailItem.Body    = catchedException.ToString();

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

                mailItem.Send();

                recipient  = null;
                mailItem   = null;
                outlookApp = null;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemple #5
0
        private bool TryAddRecipientInModule(string moduleName, CrmId meetingId, Outlook.Recipient recipient)
        {
            bool  result;
            CrmId id = SetCrmRelationshipFromOutlook(this, meetingId, recipient, moduleName);

            if (CrmId.IsValid(id))
            {
                string smtpAddress = recipient.GetSmtpAddress();

                this.CacheAddressResolutionData(
                    new AddressResolutionData(moduleName, id, smtpAddress));

                CrmId accountId = CrmId.Get(RestAPIWrapper.GetRelationship(
                                                ContactSynchroniser.CrmModule, id.ToString(), "accounts"));

                if (CrmId.IsValid(accountId) &&
                    SetCrmRelationshipFromOutlook(this, meetingId, "Accounts", accountId))
                {
                    this.CacheAddressResolutionData(
                        new AddressResolutionData("Accounts", accountId, smtpAddress));
                }

                result = true;
            }
            else
            {
                result = false;
            }

            return(result);
        }
        private string GetSenderEmailAddress()
        {
            Outlook.Recipient sender            = Application.Session.CurrentUser;
            dynamic           senderSmtpAddress = sender.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E");

            return(senderSmtpAddress.Trim());
        }
Exemple #7
0
 /// <summary>
 /// Check if this email exists in the user directory
 /// </summary>
 /// <param name="email"></param>
 /// <returns></returns>
 private bool _ResolveEmail(string email)
 {
     if (String.IsNullOrEmpty(email))
     {
         return(false);
     }
     if (ConnectToServer() == false)
     {
         return(false);
     }
     Outlook.Recipient rcp = null;
     try
     {
         rcp = outlookObj.GetNamespace("MAPI").CreateRecipient(email);
         rcp.Resolve();
         if (rcp != null && rcp.Resolved)
         {
             return(true);
         }
     }
     catch
     {
         return(false);
     }
     finally
     {
         if (rcp != null)
         {
             Marshal.ReleaseComObject(rcp);
         }
     }
     return(false);
 }
        public static Boolean SendOutlookMail(string recipient, string subject, string body)
        {
            try
            {
                Outlook.Application outlookApp = new Outlook.Application();
                Outlook._MailItem   oMailItem  = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                Outlook.Inspector   oInspector = oMailItem.GetInspector;

                Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
                Outlook.Recipient  oRecip  = (Outlook.Recipient)oRecips.Add(recipient);
                oRecip.Resolve();

                if (subject != "")
                {
                    oMailItem.Subject = subject;
                }
                if (body != "")
                {
                    oMailItem.Body = body;
                }
                oMailItem.Display(true);
                return(true);
            }
            catch (Exception objEx)
            {
                MessageBox.Show(objEx.ToString());
                return(false);
            }
        }
Exemple #9
0
        /// <summary>
        /// link to staff information setting function
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SendEmail_Click(object sender, EventArgs e)
        {
            try
            {
                Outlook.Application oApp = new Outlook.Application();

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

                Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add(showStaffInfo.Email);
                oRecip.Resolve();

                oMsg.Subject  = "annual leave remind";
                oMsg.HTMLBody = "Dear " + showStaffInfo.StaffName + ",<br/><br/>" +
                                " We kindly remind you that Your last year’s  Annual Leave still have " + showStaffInfo.LastyearRemains + " days left. It will be cleared  on  April 1st . <br/><br/>" +
                                "Best Regards<br/><br/>" +
                                "_____________________________________________<br/>" +
                                "Allen Wang<br/><br/>" +
                                "VOLVO Information Technology (TianJian)Co.,Ltd<br/>" +
                                "Telephone: +86-22-84808128<br/>" +
                                "Telefax:    +86-22-84808480<br/>" +
                                "E-mail: [email protected]<br/>";

                oMsg.Display(true);

                oRecip = null;
                oMsg   = null;
                oApp   = null;
            }

            catch (Exception ex)
            {
                MessageBox.Show("Error!" + ex);
            }
        }
Exemple #10
0
        public void Button_Click(Office.IRibbonControl control)
        {
            try
            {
                Outlook.Recipient  recipient  = null;
                Outlook.Recipients recipients = null;

                Outlook.Application application = new Outlook.Application();
                Outlook.Explorer    explorer    = application.ActiveExplorer();
                Outlook.Inspector   inspector   = application.ActiveInspector();
                inspector.Activate();
                Outlook._MailItem mailItem = inspector.CurrentItem;

                //Outlook.Application outlookApplication = new Outlook.Application();
                //Outlook.MailItem mail = (Outlook.MailItem)outlookApplication.ActiveInspector().CurrentItem;

                if (mailItem != null)
                {
                    recipients = mailItem.Recipients;
                    recipients.ResolveAll();
                    String       StrR            = "";
                    const string PR_SMTP_ADDRESS =
                        "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
                    foreach (Outlook.Recipient recip in recipients)
                    {
                        Outlook.PropertyAccessor pa = recip.PropertyAccessor;
                        string smtpAddress          =
                            pa.GetProperty(PR_SMTP_ADDRESS).ToString();

                        string[] strsplit = smtpAddress.Split('@');
                        if (!StrR.Contains(strsplit[1]))
                        {
                            StrR += strsplit[1] + Environment.NewLine;
                        }
                    }
                    if (StrR != string.Empty)
                    {
                        MyMessageBox ObjMyMessageBox = new MyMessageBox();
                        ObjMyMessageBox.ShowBox(StrR);
                    }



                    //recipient.Resolve();
                    //                DialogResult result = MessageBox.Show("Are you sure you want to send emails to the following domains " + StrR, "Varify Domains ",
                    //MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    //                if (result == DialogResult.Yes)
                    //                {
                    //                    //code for Yes
                    //                }
                    //                else
                    //                {

                    //                }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #11
0
        public void Dispose()
        {
            try
            {
                if (_serverType == MailServerType.SMTP)
                {
                    if (_netMail != null)
                    {
                        _netMail.Dispose();
                        _netMail = null;
                    }
                }
                else
                {
#if OUTLOOK
                    // Log off.
                    _oNS.Logoff();

                    // Clean up.
                    _oRecip  = null;
                    _oRecips = null;
                    _oMsg    = null;
                    _oNS     = null;
                    _oApp    = null;
#endif
                }

                GC.Collect();

                GC.SuppressFinalize(this);
            }
            catch
            {
            }
        }
Exemple #12
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) {}
 }
        internal static void AddBcc(Outlook.MailItem mailItem, ref bool Cancel)
        {
            Debug.Assert(mailItem != null);

            if (Config.EnableAutoBcc == true)
            {
                if (mailItem != null)
                {
                    // TODO: if strBcc == "", the following line will raise an exception, why?
                    Outlook.Recipient objRecip = mailItem.Recipients.Add(Config.AutoBccEmailAddress);
                    objRecip.Type = (int)Outlook.OlMailRecipientType.olBCC;

                    if (objRecip.Resolve() == false)
                    {
                        DialogResult result =
                            MessageBox.Show("Could not resolve the Bcc recipient. Do you still want to send the message ?",
                                            "Could Not Resolve Bcc Recipient",
                                            MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question,
                                            MessageBoxDefaultButton.Button2);
                        if (result == DialogResult.No)
                        {
                            Cancel = true;
                        }
                    }
                }
            }
        }
Exemple #14
0
        private void Email(string subject, string body, string recipient)
        {
            try
            {
                Outlook.Application oApp;
                Outlook.MailItem    oMsg;
                OutlookApp(out oApp, out oMsg);

                Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add(recipient);
                oRecip.Resolve();

                oMsg.Subject = subject;
                oMsg.Body    = body;

                oMsg.Save();
                oMsg.Send();

                oRecip = null;
                oMsg   = null;
                oApp   = null;
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool SendMail(DbEmail email)
        {
            Outlook.Attachment oAttach;
            try
            {
                // Create the Outlook application by using inline initialization.
                Outlook.Application oApp = new Outlook.Application();

                //Create the new message by using the simplest approach.
                Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

                //Add a recipient
                Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add(email.Recipient);
                oRecip.Resolve();

                //Set the basic properties.
                oMsg.Subject = email.Subject;
                oMsg.Body    = email.Body;

                //Add an attachment

                //if (email.Attachments.Count > 0)
                //{
                //    for (int i = 0; i < email.Attachments.Count(); i++)
                //    {
                //        String sSource = email.Attachments[i];
                //        String sDisplayName = email.Subject;
                //        int iPosition = (int)oMsg.Body.Length + 1;
                //        int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                //        oAttach = oMsg.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName);
                //    }
                //}


                // If you want to, display the message.
                // oMsg.Display(true);  //modal

                //Send the message.
                oMsg.Save();
                //(oMsg as _Outlook.MailItem).Send();
                //Outlook.Account account = oApp.Session.Accounts[email.Sender];
                //oMsg.SendUsingAccount = account;
                ((Outlook._MailItem)oMsg).Send();


                //Explicitly release objects.
                oRecip  = null;
                oAttach = null;
                oMsg    = null;
                oApp    = null;

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //Label1.Text = ex.Message + ex.StackTrace;
                return(false);
            }
        }
Exemple #16
0
        //gavdcodeend 08

        //gavdcodebegin 09
        private void btnCreateAppointment_Click(object sender, RibbonControlEventArgs e)
        {
            Outlook.Application myApplication = Globals.ThisAddIn.Application;

            Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)
                                                     myApplication.CreateItem(Outlook.OlItemType.olAppointmentItem);

            newAppointment.Start       = DateTime.Now.AddHours(1);
            newAppointment.End         = DateTime.Now.AddHours(2);
            newAppointment.Location    = "An Empty Room";
            newAppointment.Body        = "This is a test appointment";
            newAppointment.AllDayEvent = false;
            newAppointment.Subject     = "My test";
            newAppointment.Recipients.Add("Somebody, He Is");

            Outlook.Recipients sentAppointmentTo = newAppointment.Recipients;
            Outlook.Recipient  sentInvite        = null;
            sentInvite      = sentAppointmentTo.Add("b, bbb b");
            sentInvite.Type = (int)Outlook.OlMeetingRecipientType.olRequired;
            sentInvite      = sentAppointmentTo.Add("c, ccc c");
            sentInvite.Type = (int)Outlook.OlMeetingRecipientType.olOptional;
            sentAppointmentTo.ResolveAll();
            newAppointment.Save();
            newAppointment.Display(true);
        }
        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 #18
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;
        }
        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 #20
0
        private async Task CheckRecipientsInContactsAsync(string emailAddress, Outlook.Folder contacts, Outlook.MailItem mail)
        {
            //Loop till the toEmail found in the contacts list - once contact found loop will break and run for another recipient
            foreach (Outlook.ContactItem contactItem in contacts.Items)
            {
                #region Logic for removing the email address from the contactItem so that it matches parameter emailAddress

                string Email1DisplayName = string.Empty;
                string Email2DisplayName = string.Empty;
                string Email3DisplayName = string.Empty;

                //Checking the Email address is of type "SMTP" or "EX"
                if (!string.IsNullOrEmpty(contactItem.Email1Address))
                {
                    Email1DisplayName = contactItem.Email1AddressType == "SMTP" ? contactItem.Email1Address.Trim() : GetSmtpEmaillAddress(contactItem);
                }

                if (!string.IsNullOrEmpty(contactItem.Email2Address))
                {
                    Email2DisplayName = contactItem.Email1AddressType == "SMTP" ? contactItem.Email1Address.Trim() : GetSmtpEmaillAddress(contactItem);
                }

                if (!string.IsNullOrEmpty(contactItem.Email3Address))
                {
                    Email3DisplayName = contactItem.Email1AddressType == "SMTP" ? contactItem.Email1Address.Trim() : GetSmtpEmaillAddress(contactItem);
                }

                #endregion

                //Check the toEmail matches the contact's email and display name
                if (emailAddress == Email1DisplayName || emailAddress == Email2DisplayName || emailAddress == Email3DisplayName)
                {
                    //getting the email address from the contact instead of displayName
                    string contactEmailAddress = string.Empty;

                    contactEmailAddress = !string.IsNullOrWhiteSpace(Email1DisplayName.Trim()) ? Email1DisplayName.Trim() : !string.IsNullOrWhiteSpace(Email2DisplayName.Trim()) ? Email2DisplayName.Trim() : !string.IsNullOrWhiteSpace(Email3DisplayName.Trim()) ? Email3DisplayName.Trim() : Email3DisplayName.Trim();

                    //Check the user defined property "SendViaClearMessage" exists for the contact
                    var CustomProperty = contactItem.UserProperties.Find("SendViaClearMessage", true);
                    if (CustomProperty != null)
                    {
                        if (contactItem.UserProperties["SendViaClearMessage"].Value)
                        {
                            //Adding the Clear Message recipients to the list for saving the email in sent items with all emails
                            cmRecipientsList.Add(emailAddress);

                            //The call for the adding the clear message object once found true for the property
                            PerpareClearMessageModel(contactEmailAddress, mail);
                        }
                        else
                        {
                            //Else add the recipient to the normal outlook recipient for sending email (w/o clear message)
                            olRecipientTO      = olRecipients.Add(emailAddress);
                            olRecipientTO.Type = 1;
                        }
                    }
                    break;
                }
            }
        }
 //<Snippet1>
 private void AddAppointment()
 {
     try
     {
         Outlook.AppointmentItem newAppointment =
             (Outlook.AppointmentItem)
             this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem);
         newAppointment.Start    = DateTime.Now.AddHours(2);
         newAppointment.End      = DateTime.Now.AddHours(3);
         newAppointment.Location = "ConferenceRoom #2345";
         newAppointment.Body     =
             "We will discuss progress on the group project.";
         newAppointment.AllDayEvent = false;
         newAppointment.Subject     = "Group Project";
         newAppointment.Recipients.Add("Roger Harui");
         Outlook.Recipients sentTo     = newAppointment.Recipients;
         Outlook.Recipient  sentInvite = null;
         sentInvite      = sentTo.Add("Holly Holt");
         sentInvite.Type = (int)Outlook.OlMeetingRecipientType
                           .olRequired;
         sentInvite      = sentTo.Add("David Junca ");
         sentInvite.Type = (int)Outlook.OlMeetingRecipientType
                           .olOptional;
         sentTo.ResolveAll();
         newAppointment.Save();
         newAppointment.Display(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show("The following error occurred: " + ex.Message);
     }
 }
Exemple #22
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 #23
0
 protected void ButtonSendMail_Click(object sender, EventArgs e)
 {
     try
     {
         List <string> lstAllRecipients = new List <string>();
         //Below is hardcoded - can be replaced with db data
         lstAllRecipients.Add("*****@*****.**");
         lstAllRecipients.Add("*****@*****.**");
         Outlook.Application outlookApp = new Outlook.Application();
         Outlook._MailItem   oMailItem  = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
         Outlook.Inspector   oInspector = oMailItem.GetInspector;
         // Thread.Sleep(10000);
         // Recipient
         Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
         foreach (String recipient in lstAllRecipients)
         {
             Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
             oRecip.Resolve();
         }
         //Add CC
         Outlook.Recipient oCCRecip = oRecips.Add("*****@*****.**");
         oCCRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
         oCCRecip.Resolve();
         //Add Subject
         oMailItem.Subject = "Test Mail";
         // body, bcc etc...
         //Display the mailbox
         oMailItem.Display(true);
     }
     catch (Exception objEx)
     {
         Response.Write(objEx.ToString());
     }
 }
Exemple #24
0
 public static bool GetEmailFromName(this Recipient recipient, out string name, out string email)
 {
     name  = null;
     email = null;
     try
     {
         if (!string.IsNullOrEmpty(recipient.Name) && recipient.Name.Contains("<") &&
             recipient.Name.Contains(">"))
         {
             var startIndex = recipient.Name.LastIndexOf("<");
             var endIndex   = recipient.Name.LastIndexOf(">");
             if (startIndex < endIndex)
             {
                 email = recipient.Name.Substring(startIndex + 1, endIndex - startIndex - 1);
                 if (email.IsValidEmailAddress())
                 {
                     name = recipient.Name.Substring(0, startIndex);
                     return(true);
                 }
             }
         }
     }
     catch
     {
         return(false);
     }
     return(false);
 }
Exemple #25
0
        /// <summary>
        /// TaskItemから、宛先(Recipient)のリスト取得する
        /// </summary>
        /// <param name="Item">TaskItemオブジェクト</param>
        /// <returns>List<Outlook.Recipient></returns>
        private static List <Outlook.Recipient> GetRecipientList(Outlook.TaskItem item)
        {
            Outlook.Recipients       recipients     = item.Recipients;
            List <Outlook.Recipient> recipientsList = new List <Outlook.Recipient>();

            if (IsSendTaskRequest(item))
            {
                //これから送信するTaskRequestItem
                for (int i = 1; i <= recipients.Count; i++)
                {
                    recipientsList.Add(recipients[i]);
                }
            }
            else
            {
                //受信したTaskRequestItem
                if (item.Owner == null)
                {
                    recipientsList.Add(item.Recipients[1]);
                }
                else
                {
                    Outlook.Recipient ownerRecipient = Globals.ThisAddIn.Application.Session.CreateRecipient(item.Owner);
                    recipientsList.Add(ownerRecipient);
                }
            }
            return(recipientsList);
        }
Exemple #26
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 #27
0
        public static int SendEmail(string password)
        {
            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 HTMLBody.
                //add the body of the email
                oMsg.HTMLBody = String.Format("Dear All, a new password was created upon your request ({0}) on ({1}).", password, GetTime());

                //Subject line
                oMsg.Subject = "New password";

                // Add a recipient.
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;

                // Change the recipient in the next line if necessary
                string            ToEmail = "*****@*****.**";
                Outlook.Recipient oRecip  = (Outlook.Recipient)oRecips.Add(ToEmail);
                oRecip.Resolve();

                // Send.
                ((Outlook._MailItem)oMsg).Send();
                WriteLog(String.Format("Email sent to ({0}) asking for new password ({1}) on ({2}) .", ToEmail, password, GetTime()));
                System.Threading.Thread.Sleep(1000);

                return(1);
            } catch (Exception exc) {
                WriteLog(String.Format("Error in email sending was due to: {0}", exc.ToString()));
                return(0);
            }
        }
Exemple #28
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
 }
        public static int sendEmail(String fileName)
        {
            try {
                Outlook.Application oApp = new Outlook.Application();

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

                string toEmail = ConfigurationManager.AppSettings["to"].ToString();

                oMsg.HTMLBody = String.Format("Dear Eng. {0}, please find the attachements below.", toEmail);

                Outlook.Attachment oAttach = oMsg.Attachments.Add(fileName);

                oMsg.Subject = String.Format("XXXX & YYYYY for {0}", getTime());

                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;

                Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("XXXXYYYY");
                oRecip.Resolve();

                ((Outlook._MailItem)oMsg).Send();
                writeLog(String.Format("Email sent is successfully sent for {0}.", getTime()));
                System.Threading.Thread.Sleep(1000);

                // Clean up.
                oRecip  = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;
                return(1);
            } catch (Exception exc) {
                writeLog(exc.Message);
                return(0);
            }
        }
Exemple #30
0
        /// <summary>
        /// Crée un message avec des paramètres spécifques.
        /// </summary>
        /// <remarks>
        /// Crée un message avec un template HTML.
        /// </remarks>
        /// <param name="_bodyMessage">Corps, destinataire et sujet du message</param>
        /// <returns>_MailItem : Réussite -> Message créée. Echec -> Valeur null.</returns>
        /// <exception cref="Outlook.Application, StreamReader, MailDefinition, MailMessage">
        /// Exception levée par l'objet Outlook.Application, StreamReader, MailDefinition ou MailMessage.
        /// </exception>
        private static _MailItem CreateMessage(List <string> _bodyMessage)
        {
            List <string> bodyMessage = _bodyMessage;

            try
            {
                // Crée l'application Outlook.
                Outlook.Application outlookApp = new Outlook.Application();

                // Crée un nouvel email.
                Outlook.MailItem message = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

                // Ajoute des destinataires.
                Outlook.Recipients recipients = (Outlook.Recipients)message.Recipients;
                Outlook.Recipient  recipient  = (Outlook.Recipient)recipients.Add(bodyMessage[0]);
                recipient.Resolve();

                // Assigne l'objet du message.
                message.Subject = bodyMessage[2];

                // Assigne le contenu de l'email.
                message.BodyFormat           = OlBodyFormat.olFormatHTML;
                message.HTMLBody             = bodyMessage[1];
                message.ReadReceiptRequested = true;

                return(message);
            }
            catch
            {
                // Affichage d'un message d'erreur.
                MessageBox.Show(SentOffer_Err.Default.CreateMessage, SentOffer_Err.Default.ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
        private void SetAppointmentOrganizer(AppointmentItem appItem, Recipient organizer)
        {
            try
            {
                if (appItem == null || organizer == null || !SetOrganizer)
                    return;

                const string PR_SENT_REPRESENTING_NAME = "http://schemas.microsoft.com/mapi/proptag/0x0042001F";
                const string PR_SENT_REPRESENTING_ENTRY_ID = "http://schemas.microsoft.com/mapi/proptag/0x00410102";
                const string PR_SENDER_ENTRYID = "http://schemas.microsoft.com/mapi/proptag/0x0C190102";
                
                PropertyAccessor pa = appItem.PropertyAccessor;
                pa.SetProperty(PR_SENDER_ENTRYID, pa.StringToBinary(organizer.EntryID));
                pa.SetProperty(PR_SENT_REPRESENTING_NAME, organizer.Name);
                pa.SetProperty(PR_SENT_REPRESENTING_ENTRY_ID, pa.StringToBinary(organizer.EntryID));
                
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
        private string GetSMTPAddressForRecipients(Recipient recip)
        {
            const string PR_SMTP_ADDRESS =
                "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

            var pa = recip.PropertyAccessor;
            var smtpAddress = "*****@*****.**";
            try
            {
                smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString();
            }
            catch (Exception exception)
            {
                Logger.Warn(
                    $"Unable to retrieve Email for the User : {recip.Name}{Environment.NewLine}{exception.Message}");
            }
            return smtpAddress;
        }