Exemplo n.º 1
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) {}
 }
Exemplo n.º 2
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
 }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
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;
            }
        }
Exemplo n.º 6
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());
     }
 }
Exemplo n.º 7
0
        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;
                        }
                    }
                }
            }
        }
        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);
        }
        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();
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
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);
            }
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 16
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
 }
Exemplo n.º 17
0
        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);
            }
        }
Exemplo n.º 18
0
        private void SendNotifications(KeyValuePair <string, List <SVNLog> > item, Preferences preferences, Action <Exception> ExceptionCallback)
        {
            Outlook.Application application = null;
            Outlook.MailItem    mailItem    = null;
            Outlook.Recipients  recipients  = null;
            Outlook.Recipient   recipient   = null;
            try
            {
                if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
                {
                    application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
                }
                else
                {
                    application = new Outlook.Application();
                }

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

                recipients = (Outlook.Recipients)mailItem.Recipients;

                recipient      = (Outlook.Recipient)recipients.Add(string.Format("{0}@{1}", item.Key, preferences.Domain));
                recipient.Type = (int)Outlook.OlMailRecipientType.olTo;
                recipient.Resolve();

                recipient      = (Outlook.Recipient)recipients.Add(preferences.CCMailTo);
                recipient.Type = (int)Outlook.OlMailRecipientType.olCC;
                recipient.Resolve();

                mailItem.Subject  = preferences.MailSubject;
                mailItem.HTMLBody = string.Format("<html><body style=\"color: #005180;\">Hi,<br/>{0}<br/><br/><table border=\"1\"><col widtd=\"55\"><col widtd=\"100\"><col widtd=\"135\"><col widtd=\"225\"><col widtd=\"225\"><tr><td BGCOLOR=\"#0C2654;\" style=\"color: #000000;\"><b>Revision<b></td><td BGCOLOR=\"#0C2654;\" style=\"color: #000000;\"><b>Author<b></td> <td BGCOLOR=\"#0C2654;\" style=\"color: #000000;\"><b>Date<b></td><td BGCOLOR=\"#0C2654;\" style=\"color: #000000;\"><b>Message<b></td><td BGCOLOR=\"#0C2654;\" style=\"color: #000000;\"<b>Reviewer Comment<b></td><td BGCOLOR=\"#0C2654;\" style=\"color: #000000;\"><b>Action(s)<b></td></tr>{1}</table><br/>Regards,<br/>{2}</body></html>", "Please correct below SVN log comment(s):", FormatMailBody(item.Value), preferences.Signature);

                (mailItem as Outlook._MailItem).Send();
            }
            catch (Exception exeption)
            {
                ExceptionCallback(exeption);
            }
            finally
            {
                recipient   = null;
                recipients  = null;
                mailItem    = null;
                application = null;
            }
        }
Exemplo n.º 19
0
        } /* AddAddress */

        private string GetEmailAddressFromExchange(string emailName)
        {
            ObjOutlook.MailItem  loDummyMsg = (ObjOutlook.MailItem)App.CreateItem(ObjOutlook.OlItemType.olMailItem);
            ObjOutlook.Recipient loAddress  = loDummyMsg.Recipients.Add(emailName);
            loAddress.Resolve();
            string SMTPAddress = GetMAPIProperty(loAddress.AddressEntry.MAPIOBJECT, PR_SMTP_ADDRESS);

            return(SMTPAddress);
        }
Exemplo n.º 20
0
        private Boolean sendMail()
        {
            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);
                Outlook.Inspector oInspector = oMsg.GetInspector;
                // Set HTMLBody.
                //add the body of the email
                oMsg.HTMLBody = string.Format(GetLabel("Mail.0001"), txFor.Text, txFor.Text, txReason.Text, FormUser.FirstName + " " + FormUser.LastName);
                //Add an attachment.
                //String sDisplayName = "MyAttachment";
                //int iPosition = (int)oMsg.Body.Length + 1;
                //int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                //now attached the file
                //Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName);
                //Subject line
                oMsg.Subject = string.Format(GetLabel("Mail.0002"), txFor.Text);
                // Add a recipient.
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                //oRecips.Add(mailAlias);
                //oRecips.ResolveAll();
                // Change the recipient in the next line if necessary.
                //Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(mailAlias);
                string[] alias = mailAlias.Split(new string[] { "," }, StringSplitOptions.None);
                foreach (String recipient in alias)
                {
                    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);

                    if (!oRecip.Resolve())
                    {
                        oRecips.Remove(oRecips.Count);
                    }
                }
                //oRecip.Resolve();
                // Send.
                oMsg.Send();
                // Clean up.
                //oRecip = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;

                return(true);
            }//end of try block
            catch (Exception ex)
            {
                mailError = ex.Message;
                return(false);
            }
        }
Exemplo n.º 21
0
 public void CreateMailItem(String email, String path)
 {
     mail         = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Outlook.MailItem;
     mail.Subject = Subject;
     mail.Body    = EmailBody;
     Outlook.Attachment attach = mail.Attachments.Add(path);
     mailrecipents = mail.Recipients;
     rec           = mailrecipents.Add(email);
     rec.Resolve();
     mail.Send();
 }
Exemplo n.º 22
0
        private void buttonSend_Click(object sender, System.EventArgs e)
        {
            //string htmltext = editor1.Html.ToString();
            //System.IO.File.WriteAllText(@"C:\Users\HP\Desktop\htmltext.txt", htmltext);

            if (sendNum != 0)
            {
                if ((textTO.Text == null) || (textSubject.Text == null))
                {
                    return;
                }
                if ((textTO.Text.Length == 0) || (textSubject.Text.Length == 0))
                {
                    return;
                }

                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                Outlook.Recipient  oRecip  = (Outlook.Recipient)oRecips.Add(textTO.Text);

                if (textCC.Text != null)
                {
                    if (textCC.Text.Length > 0)
                    {
                        Outlook.Recipients ccRecips = (Outlook.Recipients)oMsg.Recipients;
                        Outlook.Recipient  ccRecip  = (Outlook.Recipient)ccRecips.Add(textTO.Text);
                        ccRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
                    }
                    //ma.AddRecip(textCC.Text, null, true);
                }

                oMsg.Subject = textSubject.Text;

                oMsg.HTMLBody = editor1.Html;
                //if (!ma.Send(textSubject.Text, textMail.Text))
                //    MessageBox.Show(this, "MAPISendMail failed! " + ma.Error(), "Send Mail", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                oRecip.Resolve();
                // Send.
                oMsg.Send();

                // Log off.
                oNS.Logoff();

                // Clean up.
                oRecip  = null;
                oRecips = null;
                oMsg    = null;
                oNS     = null;
                oApp    = null;

                ma.Reset();
                this.Close();
            }
        }
Exemplo n.º 23
0
        }//end of Email Method

        public static bool sendHtmlEMailThroughOUTLOOK(string _RecipientEmail, string _EmailSubject, string _EmailBody)
        {
            bool check = false;

            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);
                //Outlook.MailItem oMsg = (Outlook.MailItem)Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);

                //Add a recipient.
                // TODO: Change the following recipient where appropriate.
                Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add(_RecipientEmail);
                oRecip.Resolve();

                //Set the basic properties.
                oMsg.Subject  = _EmailSubject;
                oMsg.HTMLBody = _EmailBody;

                //Add an attachment.
                // TODO: change file path where appropriate

                //String sSource = "C:\\setupxlg.txt";
                //String sDisplayName = "MyFirstAttachment";
                //int iPosition = (int)oMsg.Body.Length + 1;
                //int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                //Outlook.Attachment 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.Send();

                //Explicitly release objects.
                oRecip = null;
                //oAttach = null;
                oMsg  = null;
                oApp  = null;
                check = true;
            }//end of try block
            catch (Exception ex)
            {
                check = false;
            }//end of catch

            return(check);
        }//end of Email Method
Exemplo n.º 24
0
        public static void sendEMailThroughOUTLOOK()
        {
            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
                //      "Dear Admin, You have recieved an enquiry onyour Website. Following are the details of enquiry:<br/><br/>Name: " + TextBox2.Text + "<br/>Address: " + TextBox3.Text + ", " + TextBox4.Text + "<br/>Phone: " + TextBox5.Text + "<br/>Email: " + TextBox2.Text + "<br/>Query: " + TextBox6.Text+"<br/> Regards, <br/> Veritas Team"
                oMsg.HTMLBody = "Hi,\n \n <br/> <br/>Automation Execution has been started \n<br/><br/> Thanks & Regards \n<br/> Raghu Ram Reddy<br/><br/><br/>***This is an Auto generated mail***";
                //  oMsg.HTMLBody = "Automation Execution has been started!!";
                //Add an attachment.
                String sDisplayName = "MyAttachment";
                int    iPosition    = (int)oMsg.Body.Length + 1;
                int    iAttachType  = (int)Outlook.OlAttachmentType.olByValue;
                //   now attached the file
                Outlook.Attachment oAttach = oMsg.Attachments.Add(@"D:\\Suite_Driver.xlsx", iAttachType, iPosition, sDisplayName);
                //Subject line

                oMsg.Subject = "Automation Execution has been started!!";

                //    Outlook.MailItem mail;


                // 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("*****@*****.**");
                //    oRecip.Resolve();

                Outlook.Recipient oRecip2 = (Outlook.Recipient)oRecips.Add("*****@*****.**");
                oRecip2.Resolve();

                //Outlook.Recipient oRecip3 = (Outlook.Recipient)oRecips.Add("*****@*****.**");
                //oRecip3.Resolve();

                // Send.
                oMsg.Send();
                // Clean up.
                oRecip2 = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;
            }//end of try block
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            } //end of catch
        }     //end of Email Method
Exemplo n.º 25
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            Outlook.DistListItem myList;
            foreach (Outlook.DistListItem distList in Globals.ThisAddIn.ListsFolder.Items)
            {
                distList.Delete();
            }

            int max = Globals.ThisAddIn.ContactsFolder.Items.OfType <Outlook.ContactItem>().Count();
            int ctr = 0;

            foreach (Outlook.ContactItem contact in Globals.ThisAddIn.ContactsFolder.Items.OfType <Outlook.ContactItem>())
            {
                ctr++;
                backgroundWorker1.ReportProgress(ctr);
                Application.DoEvents();

                // only process contacts with an email address
                if (contact.Email1Address != null)
                {
                    // create a Recipient for this contact
                    Outlook.Recipient myRecipient = Globals.ThisAddIn.Application.Session.CreateRecipient(contact.Email1Address.ToString());
                    myRecipient.Resolve();

                    // add to relevant DistListItems according to categories
                    if (contact.Categories != null)
                    {
                        var categories = contact.Categories.Split(new[] { "; " }, StringSplitOptions.None);
                        foreach (string category in categories)
                        {
                            if (!Globals.ThisAddIn.DistLists.Exists(x => x.DLName == "VL." + category))
                            {
                                // DistListItem needs to be created
                                myList        = Globals.ThisAddIn.ListsFolder.Items.Add(Outlook.OlItemType.olDistributionListItem) as Outlook.DistListItem;
                                myList.DLName = "VL." + category;
                                myList.Body   = "Dies ist eine automatisch erzeugte Liste. Sie sollte nicht von Hand geändert werden, da beim nächsten Update alle Änderungen überschrieben würden.";
                                myList.Save();
                                Globals.ThisAddIn.DistLists.Add(myList);
                            }
                            else
                            {
                                // DistListItem is already present
                                myList = Globals.ThisAddIn.DistLists.Find(x => x.DLName == "VL." + category);
                            }
                            myList.AddMember(myRecipient);
                            myList.Save();
                        }
                    }
                }
            }
        }
Exemplo n.º 26
0
        private void btnFromAlias_Click(object sender, RoutedEventArgs e)
        {
            _seenDLs = new List <Outlook.AddressEntry>(); // TODO: this should only happpen once (perhaps at Enum with empty prefix?)
            lstMembers.Items.Clear();

            var alias = txtAlias.Text.Trim();

            // this is really crappy logic - if the user did not supply a valid email address use their's
            if (!EmailValidator.IsValid(alias))
            {
                var user = _outlook.Application.Session.CurrentUser.AddressEntry.GetExchangeUser();
                if (user != null && user.PrimarySmtpAddress != null)
                {
                    var domain = user.PrimarySmtpAddress.Split('@')[1];
                    alias += "@" + domain;
                }
            }

            // Get an address entry from this alias - it looks like the easiest way to do this is to add
            // this to a mail item and then get Outlook to handle resolving it
            var item = _outlook.CreateItem(Outlook.OlItemType.olMailItem);

            Outlook.Recipient recipient = item.Recipients.Add(alias);
            recipient.Resolve();

            // delete the mail item
            item.Delete();

            System.Diagnostics.Debug.WriteLine(recipient.AddressEntry.Address + "   " + recipient.AddressEntry.Name);

            if (recipient != null)
            {
                var address = recipient.AddressEntry;

                if (address == null)
                {
                    System.Diagnostics.Debug.WriteLine("not found");
                }
                else if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry)
                {
                    EnumerateDL(address);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Not a DL");
                }
            }

            // TODO: /facepalm :(
            txtTotalMembers.Text = "Total Members: " + lstMembers.Items.Count;
        }
Exemplo n.º 27
0
        public static void SendEmailUsingOUTLOOK(string attachmentName)
        {
            string sonarUrl = ConfigurationManager.AppSettings["sonarUrl"];

            string mailFrom = ConfigurationManager.AppSettings["mailFrom"];
            string mailTo   = ConfigurationManager.AppSettings["mailTo"];

            try
            {
                Log("Preparing mail..\n");
                // 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
                var dateFormat = ConfigurationManager.AppSettings["DateFormat"].ToString();
                oMsg.HTMLBody = ConfigurationManager.AppSettings["mailBody"].ToString().Replace("REPORTDATE", DateTime.Now.ToString(dateFormat)).Replace("SONARURL", sonarUrl);
                //"Hi Team,<br>" + ConfigurationManager.AppSettings["mailSubject"] + DateTime.Now.ToString("MMM yyyy");
                //Add an attachment.
                // String sDisplayName = string.Format("{0}", attachmentName);
                int iPosition   = (int)oMsg.Body.Length + 1;
                int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                //now attached the file
                Outlook.Attachment oAttach = oMsg.Attachments.Add
                                                 (attachmentName, iAttachType, iPosition);

                //Subject line
                oMsg.Subject = ConfigurationManager.AppSettings["mailSubject"].Replace("REPORTDATE", DateTime.Now.ToString(dateFormat));
                // 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(mailTo);
                oRecip.Resolve();
                // Send.
                oMsg.Send();
                // Clean up.
                oRecip  = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;

                Log(string.Format("Email sent sucessfully to {0}", mailTo));
            }//end of try block
            catch
            {
                Log($"Email sending failed \n From :{mailFrom} To :{mailTo}");
                throw;
            } //end of catch
        }     //end of Em
Exemplo n.º 28
0
        public static int Main(string[] args)
        {
            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.
                // TODO: Change the following recipient where appropriate.
                Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add("e-mail address");
                oRecip.Resolve();

                //Set the basic properties.
                oMsg.Subject = "This is the subject of the test message";
                oMsg.Body    = "This is the text in the message.";

                //Add an attachment.
                // TODO: change file path where appropriate
                String             sSource      = "C:\\setupxlg.txt";
                String             sDisplayName = "MyFirstAttachment";
                int                iPosition    = (int)oMsg.Body.Length + 1;
                int                iAttachType  = (int)Outlook.OlAttachmentType.olByValue;
                Outlook.Attachment 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.Send();

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

            // Simple error handler.
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught: ", e);
            }

            //Default return value.
            return(0);
        }
Exemplo n.º 29
0
        private void btnSendEMail_Click(object sender, EventArgs e)
        {
            string strBody = txtBody.Text;

            strBody = strBody.Replace("\r\n", "<br />");
            string strSignature = ReadSignature();

            strBody = strBody + "<br /><br />" + strSignature;

            //OUTLOOK
            Outlook.Application oApp = new Outlook.Application();
            // Create a new mail item.
            Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMsg.HTMLBody  = "<FONT face=\"Arial\">";
            oMsg.HTMLBody += strBody.Trim();
            //Subject line
            oMsg.Subject = txtSubject.Text;
            oMsg.CC      = txtCC.Text;
            //oMsg.BCC = txtBCC.Text;
            // Add a recipient.
            Outlook.Recipients oRecips     = (Outlook.Recipients)oMsg.Recipients;
            string[]           EMAddresses = txtTo.Text.Split(";,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < EMAddresses.Length; i++)
            {
                if (EMAddresses[i].Trim() != "")
                {
                    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(EMAddresses[i]);
                    oRecip.Resolve();
                }
            }
            ////Add an attachment.
            //for (int i = 0; i < lstAttachment.Items.Count; i++)
            //{
            //    //strFile = Path.GetFileName(lstAttachment.Items[i].ToString());
            //    oMsg.Attachments.Add(lstAttachment.Items[i].ToString());
            //}
            oMsg.Attachments.Add(lnkFile.Text);
            oMsg.Display();
            ////Send.
            ////oMsg.Send();
            ////((Outlook._MailItem)oMsg).Send();

            //Clean up.
            oRecips = null;
            oMsg    = null;
            oApp    = null;
            txtSponsorID.ReadOnly = false; txtSponsor.ReadOnly = false; picSponsors.Enabled = true;
            btnEMail.Enabled      = true; btnPrtPreview.Enabled = true; btnClose.Enabled = true; pnlEMail.Enabled = false;
            txtTo.Text            = ""; txtCC.Text = ""; txtSubject.Text = ""; txtBody.Text = ""; lnkFile.Text = "Statement of Account";
        }
Exemplo n.º 30
0
    static void MailOperations()
    {
        Console.WriteLine("Do You want to Compose a Mail with the Same Excel Attachement? Press [Y] for Yes any other key for N");
        string input = Console.ReadLine();

        if (input.ToLower().Contains("y"))
        {
            try
            {
                // Create the Outlook application.
                Outlook.Application oApp = new Microsoft.Office.Interop.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
                var statusDate = StatusDate.ToString("dd MMMM");
                oMsg.Subject = "WP Daily Update – Subha Deb - " + statusDate;
                StringBuilder htmlBody = new StringBuilder();
                htmlBody.Append("Hi,<br/> <br/> PFA the Status for " + statusDate);
                htmlBody.Append("<br/> <br/> Thanks, <br> Subha Deb");
                oMsg.HTMLBody = htmlBody.ToString();
                //Add an attachment.
                int iPosition   = (int)oMsg.Body.Length + 1;
                int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                //now attached the file
                Outlook.Attachment oAttach = oMsg.Attachments.Add(GeneratedExcelFileNamePath, iAttachType, iPosition);
                // Add a recipient.
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                // Change the recipient in the next line if necessary.
                foreach (var email in ReceipentsEmailIdsList)
                {
                    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(email);
                    oRecip.Resolve();
                    oRecip = null;
                }
                oMsg.Display(true);
                // Send.
                //oMsg.Send();
                // Clean up.
                oRecips = null;
                oMsg    = null;
                oApp    = null;
            }//end of try block
            catch (Exception ex)
            {
                Console.WriteLine("Got Exception");
                Console.WriteLine(ex.ToString());
            }//end of catch
        }
    }