Ejemplo n.º 1
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
 }
Ejemplo n.º 2
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);
            }
        }
        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);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
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) {}
 }
Ejemplo n.º 9
0
        /// <summary>
        ///Refere to where the code was taken from
        ///https://www.add-in-express.com/creating-addins-blog/2011/09/08/outlook-fill-recipients-programmatically/
        /// </summary>
        /// <param name="mail"></param>
        /// <returns></returns>
        private bool AddRecipients(Outlook.MailItem mail)
        {
            bool retValue = false;
            Outlook.Recipients recipients = null;
            Outlook.Recipient recipientTo = null;
            Outlook.Recipient recipientCC = null;
            Outlook.Recipient recipientBCC = null;
            try
            {
                recipients = mail.Recipients;
                // first, we remove all the recipients of the e-mail
                while (recipients.Count != 0)
                {
                    recipients.Remove(1);
                }
                // now we add new recipietns to the e-mail
                foreach (IEmailAddress address in this.ToAddesses)
                {
                    recipientTo = recipients.Add((((EmailAddress)address).Address));
                    recipientTo.Type = (int)Outlook.OlMailRecipientType.olTo;

                }
                foreach (IEmailAddress address in this.CcAddresses)
                {
                    recipientTo = recipients.Add((((EmailAddress)address).Address));
                    recipientTo.Type = (int)Outlook.OlMailRecipientType.olCC;
                }
                foreach (IEmailAddress address in this.BccAddress)
                {
                    recipientTo = recipients.Add((((EmailAddress)address).Address));
                    recipientTo.Type = (int)Outlook.OlMailRecipientType.olBCC;
                }
                retValue = recipients.ResolveAll();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                if (recipientBCC != null) Marshal.ReleaseComObject(recipientBCC);
                if (recipientCC != null) Marshal.ReleaseComObject(recipientCC);
                if (recipientTo != null) Marshal.ReleaseComObject(recipientTo);
                if (recipients != null) Marshal.ReleaseComObject(recipients);
            }
            return retValue;
        }
Ejemplo n.º 10
0
        private void AddAppointment(string subject, string body, DateTime startdatum, DateTime sluttatum)
        {
            try
            {
                Microsoft.Office.Interop.Outlook.AppointmentItem newAppointment =
                    (Microsoft.Office.Interop.Outlook.AppointmentItem)
                    _application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
                newAppointment.Start       = startdatum;
                newAppointment.End         = sluttatum;
                newAppointment.AllDayEvent = false;
                newAppointment.BusyStatus  = Microsoft.Office.Interop.Outlook.OlBusyStatus.olTentative;
                newAppointment.Location    = "Platsangivelse...";

                // Bifoga ett dokument om så önskas
                OpenFileDialog attachment = new OpenFileDialog();
                attachment.Title = appointheader.Text;
                attachment.ShowDialog();
                if (attachment.FileName.Length > 0)
                {
                    newAppointment.Attachments.Add(attachment.FileName,
                                                   Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue,
                                                   1,
                                                   attachment.FileName);
                }

                Microsoft.Office.Interop.Outlook.Recipients sentTo     = newAppointment.Recipients;
                Microsoft.Office.Interop.Outlook.Recipient  sentInvite = null;
                sentInvite      = sentTo.Add("Holly Holt");
                sentInvite.Type = (int)Microsoft.Office.Interop.Outlook.OlMeetingRecipientType
                                  .olRequired;
                sentInvite      = sentTo.Add("David Junca ");
                sentInvite.Type = (int)Microsoft.Office.Interop.Outlook.OlMeetingRecipientType
                                  .olOptional;
                sentTo.ResolveAll();

                newAppointment.Subject = subject;
                newAppointment.Body    = body;
                newAppointment.Save();
                // newAppointment.Display(true);
                newAppointment.Close(OlInspectorClose.olSave); // Detta gör att man inte behöver stänga dialogen manuellt
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("The following error occurred: " + ex.Message);
            }
        }
Ejemplo n.º 11
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;
            }
        }
Ejemplo n.º 12
0
        private void CreateClearMessageMailItem(Outlook.MailItem mailObject)
        {
            if (mailObject is Outlook.MailItem)
            {
                Outlook.MailItem mail     = (Outlook.MailItem)mailObject;
                Outlook.Folder   contacts = (Outlook.Folder)Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);

                #region Logic for TO recipients to send ClearMessage API

                //Loop over all the "TO:" email addresses entered in the recipients
                foreach (Outlook.Recipient recipient in mail.Recipients)
                {
                    //Converting the exchange email address to SMTP email address
                    dynamic toEmail = recipient.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E");

                    //Checking if the recipient is in To address bar
                    if (recipient.Type == 1)
                    {
                        //Loop till the toEmail found in the contacts list - once contact found loop will break and run for another recipient
                        CheckRecipientsInContactsAsync(toEmail.ToString().Trim(), contacts, mail);
                    }
                    else
                    {
                        if (recipient.Type == 2) // For CC
                        {
                            //Adding the CC recipient to the outlook  olRecipientCC
                            olRecipientCC      = olRecipients.Add(toEmail.ToString().Trim());
                            olRecipientCC.Type = 2;
                        }
                        else //(recipient.Type == 3) //For BCC
                        {
                            //Adding the BCC recipient to the outlook  olRecipientBCC
                            olRecipientBCC      = olRecipients.Add(toEmail.ToString().Trim());
                            olRecipientBCC.Type = 3;
                        }
                    }
                }

                //Call for the Clear Message API method for sending emails
                SendClearMessageEmailAsync();

                #endregion
            }
        }
Ejemplo n.º 13
0
        public static bool SendMail(string htmlBody, string toEmails, string subject, string ccEmails)
        {
            MsOutlook.Application outlookApp = new MsOutlook.Application();
            if (outlookApp == null)
            {
                return(false);
            }

            // create a new mail item.
            MsOutlook.MailItem   mail         = (MsOutlook.MailItem)outlookApp.CreateItem(MsOutlook.OlItemType.olMailItem);
            MsOutlook.Recipients recipients   = mail.Recipients as MsOutlook.Recipients;
            MsOutlook.Recipient  recipientTo  = null;
            MsOutlook.Recipient  recipientCC  = null;
            MsOutlook.Recipient  recipientBCC = null;
            // set html body.
            // add the body of the email
            mail.HTMLBody   = htmlBody;
            mail.BodyFormat = MsOutlook.OlBodyFormat.olFormatHTML;
            mail.Subject    = subject;
            mail.Importance = MsOutlook.OlImportance.olImportanceNormal;
            var to = toEmails.Split(';');

            foreach (string tempTO in to)
            {
                recipientTo      = recipients.Add(tempTO);
                recipientTo.Type = (int)MsOutlook.OlMailRecipientType.olTo;
            }
            var cc = ccEmails.Split(';');

            foreach (string tempCC in cc)
            {
                recipientCC      = recipients.Add(tempCC);
                recipientCC.Type = (int)MsOutlook.OlMailRecipientType.olCC;
            }
            recipients.ResolveAll();
            mail.Send();

            mail       = null;
            outlookApp = null;
            recipients = null;
            return(true);
        }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
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();
 }
Ejemplo n.º 16
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();
            }
        }
Ejemplo n.º 17
0
 public 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
         oMsg.HTMLBody = "Hello vijay please find the document attached.";
         //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:\Users\16476\Documents\Test\vj.csv", iAttachType, iPosition, sDisplayName);
         //Subject line
         oMsg.Subject = "Monthly Report.";
         // Add a recipient.
         Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
         // Change the recipient in the next line if necessary.
         Outlook.Recipient oRecip1 = (Outlook.Recipient)oRecips.Add("*****@*****.**");
         Outlook.Recipient oRecip2 = (Outlook.Recipient)oRecips.Add("*****@*****.**");
         oRecip1.Resolve();
         oRecip2.Resolve();
         // Send.
         oMsg.Send();
         // Clean up.
         oRecip1 = null;
         oRecip2 = null;
         oRecips = null;
         oMsg    = null;
         oApp    = null;
     }//end of try block
     catch (Exception ex)
     {
     } //end of catch
 }     //end of Email Method
Ejemplo n.º 18
0
        public static int sendEmail()
        {
            try {
                string request = ConfigurationManager.AppSettings["request"].ToString();
                string ip      = getLocalIPAddress();

                Outlook.Application oApp = new Outlook.Application();

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

                oMsg.HTMLBody = String.Format("Dear All, I am sending this email requesting ({0}) permission ({1}).", request, ip);

                oMsg.Subject = String.Format("{0} Request", request);

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

                string            to = ConfigurationManager.AppSettings["to"].ToString();
                string            cc = ConfigurationManager.AppSettings["cc"].ToString();
                Outlook.Recipient oRecip;
                Outlook.Recipient oRecip1;
                if (!to.Equals(String.Empty))
                {
                    oRecip = (Outlook.Recipient)oRecips.Add(to);
                    oRecip.Resolve();
                }
                if (!cc.Equals(String.Empty))
                {
                    oRecip1 = (Outlook.Recipient)oRecips.Add(cc);
                    oRecip1.Resolve();
                }

                ((Outlook._MailItem)oMsg).Send();
                writeLog(String.Format("Email sent from ({0}) asking for ({1}) access on ({2}) to TO: ({3}) & CC: ({4}).", ip, request, getTime(), to, cc));
                System.Threading.Thread.Sleep(1000);
                return(1);
            } catch (Exception exc) {
                writeLog(exc.ToString());
                return(0);
            }
        }
Ejemplo n.º 19
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
Ejemplo n.º 20
0
        public void sendEMailThroughOUTLOOK(string e_ToList, string e_Subject, string e_Msg)
        {
            try
            {
                string[] e_recipients;
                // 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 = e_Msg;
                ////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:\\batchStart.txt", iAttachType, iPosition, sDisplayName);
                //Subject line
                oMsg.Subject = e_Subject;
                // 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(e_ToList);
                //Outlook.Recipient oRecip2 = (Outlook.Recipient)oRecips.Add("*****@*****.**");

                e_ToList     = Regex.Replace(e_ToList, ";", ",");
                e_recipients = Regex.Split(e_ToList, ",");

                foreach (string rString in e_recipients)
                {
                    oRecips.Add(rString);
                }

                //oRecips.Add(e_ToList);
                //oRecips.Add("*****@*****.**");

                //oRecip.Resolve();
                // Send.
                oMsg.Send();
                // Clean up.
                //oRecip = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;
            }//end of try block
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            } //end of catch
        }     //end of Email Method
Ejemplo n.º 21
0
        private void SetupRecipients(Outlook.Recipients recipients, string recipientStr, string recipientRequiredStr)
        {
            if (string.IsNullOrEmpty(recipientStr) && string.IsNullOrEmpty(recipientRequiredStr))
            {
                return;
            }

            GetHandledRecipients(recipientStr)?.ForEach(r =>
            {
                Outlook.Recipient recipient =
                    recipients.Add(r);
                recipient.Type =
                    (int)Outlook.OlMeetingRecipientType.olOptional;
            });
            GetHandledRecipients(recipientRequiredStr)?.ForEach(r =>
            {
                Outlook.Recipient recipient =
                    recipients.Add(r);
                recipient.Type =
                    (int)Outlook.OlMeetingRecipientType.olRequired;
            });
        }
Ejemplo n.º 22
0
        void ItemSend_BeforeSend(object item, ref bool cancel)
        {
            ThisRibbonCollection ribbonCollection =
                Globals.Ribbons[Globals.ThisAddIn.Application.ActiveInspector()];

            Outlook.MailItem mailItem = (Outlook.MailItem)item;

            // Check to see if track button is enabled.
            if (ribbonCollection.GetNotifyRibbon.trackToggleBtn.Checked)
            {
                if (mailItem != null)
                {
                    Outlook.Recipients recips      = mailItem.Recipients;
                    string[]           emailAdrses = new String[recips.Count];
                    int[] emailTypes = new int[recips.Count];
                    int   arrayItr   = 0;

                    // Lets add email addresses and their types in new arrays,
                    // modify the address and remove current recipients.
                    while (recips.Count > 0)
                    {
                        Outlook.Recipient recip = recips[1];

                        if (recip.Address.Split('@')[1].ToLower().Contains("getnotify.com"))
                        {
                            emailAdrses[arrayItr] = recip.Address;
                        }
                        else
                        {
                            emailAdrses[arrayItr] = recip.Address + ".getnotify.com";
                        }

                        emailTypes[arrayItr] = recip.Type;
                        arrayItr++;
                        recips.Remove(1);
                    }

                    // Add new recipients using the arrays we populated before.
                    for (int i = 0; i < emailAdrses.Length; i++)
                    {
                        // We use recipient's address as its name.
                        Outlook.Recipient newRecip = recips.Add(emailAdrses[i]);
                        newRecip.AddressEntry.Address = emailAdrses[i];
                        newRecip.Type = emailTypes[i];
                    }
                }
            }

            cancel = false;
        }
Ejemplo n.º 23
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";
        }
Ejemplo n.º 24
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
Ejemplo n.º 25
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
        }
    }
Ejemplo n.º 26
0
        //SMTP Authentication- Whereby an SMTP client may log in using an authentication mechanism chosen among supported by SMTP servers.
        public static void smtpMailConfiguration(string htmlBody, string displayName, string subject, string recipientGroup)
        {
            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 = htmlBody;
                //Add an attachment.
                String sDisplayName = displayName;
                int    iPosition    = (int)oMsg.Body.Length + 1;
                int    iAttachType  = (int)Outlook.OlAttachmentType.olByValue;
                string fileName     = reportZipath + ".zip";
                if (File.Exists(fileName))
                {
                    //now attached the file
                    Outlook.Attachment oAttach = oMsg.Attachments.Add
                                                     (fileName, iAttachType, iPosition, sDisplayName);
                }
                else
                {
                    Logger.log("No  HTML Report File Exists");
                }


                //Subject line
                oMsg.Subject = subject;
                // 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(recipientGroup);
                oRecip.Resolve();
                // Send.
                oMsg.Send();
                // Clean up.
                oRecip  = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;
                Logger.log("Mail Sent sucessfully");
            }//end of try block
            catch (Exception ex)
            {
                Logger.log("Error While Sending Email::" + ex.Message);
            }//end of catch
        }
Ejemplo n.º 27
0
        //method to send email to outlook
        public void SendEmailThroughOutlook(List <string> toList, string subject, string body)
        {
            try
            {
                // Create the Outlook application.
                // Create a new mail item.
                Outlook.MailItem oMsg = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                Console.WriteLine("Made outlook mailitem object");

                //Subject line
                oMsg.Subject = subject;
                // Add a recipient.
                oMsg.DeleteAfterSubmit = true;
                // Set HTMLBody.
                //add the body of the email
                oMsg.HTMLBody = body;

                Console.WriteLine("Adding recipients from list - there are " + toList.Count);
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                Console.WriteLine("======");
                // Change the recipient in the next line if necessary.
                foreach (string emailaddress in toList)
                {
                    Console.WriteLine(emailaddress);
                    if (emailaddress.Length > 2)
                    {
                        Console.WriteLine("Adding " + emailaddress + " as BCC");
                        Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(emailaddress);
                        oRecip.Type = (int)OlMailRecipientType.olBCC;
                        oRecip.Resolve();
                        oRecip = null;
                    }
                }
                Console.WriteLine("Done adding recipients, added {0} ", oRecips.Count);
                // Send.
                oMsg.Send();

                // Clean up.
                oRecips = null;
                oMsg    = null;
                //oApp = null;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("Failed to send email: " + ex.Message);
            }
        }
        public void SendEmail()
        {
            String document = @"C:\Users\Akash Paul\Testing\880c27db-6aa7-4ecb-bb9b-35f2509fc39b.pdf";
            String email    = "*****@*****.**";

            Outlook.Recipients  mailrecipient = null;
            Outlook.MailItem    mail          = null;
            Outlook.Recipient   rec           = null;
            Outlook.Application app           = new Outlook.Application();
            mail         = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Outlook.MailItem;
            mail.Subject = String.Format("Official Transcript");
            Outlook.Attachment attch = mail.Attachments.Add(document);
            mailrecipient = mail.Recipients;
            rec           = mailrecipient.Add(email);
            rec.Resolve();
            mail.Send();
        }
Ejemplo n.º 29
0
        public void SendMail(string subject, string mailBody, string toMailID)
        {
            try
            {
                // Create the Outlook application.
                Microsoft.Office.Interop.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 = subject;
                oMsg.To      = toMailID;

                // Set HTMLBody.
                String sHtml;
                //sHtml = "Please take action against below SR12345"+" <br><a href='google.com'><img src='C:\\Users\\M1054034\\Documents\\Visual Studio 2017\\Projects\\SendMail\\SendMail\\Images\\Approve.jpg'></a>" + "  "+  "<a href='google.com'><img src='C:\\Users\\M1054034\\Documents\\Visual Studio 2017\\Projects\\SendMail\\SendMail\\Images\\Reject.jpg'></a></br>";

                sHtml         = mailBody;
                oMsg.HTMLBody = sHtml;

                // Add a recipient.
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                // TODO: Change the recipient in the next line if necessary.
                Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(toMailID);
                oRecip.Resolve();

                // Send.
                oMsg.Send();

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

            // Simple error handling.
            catch (Exception e)
            {
                ViewBag.Message("Error");
            }

            // Default return value.
        }
Ejemplo n.º 30
0
        }     //end of Email Method

        public void sendEMailThroughOUTLOOK(string e_ToList, string e_Subject, string e_Msg, string e_attch)
        {
            try
            {
                string[] e_recipients;

                // 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 = e_Msg;
                //Add an attachment.
                String sDisplayName = "Client Attachment";
                int    iPosition    = (int)oMsg.Body.Length + 1;
                int    iAttachType  = (int)Outlook.OlAttachmentType.olByValue;
                //now attached the file
                Outlook.Attachment oAttach = oMsg.Attachments.Add(@e_attch, iAttachType, iPosition, sDisplayName);
                //Subject line
                oMsg.Subject = e_Subject;
                // Add a recipient.
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;

                e_ToList     = Regex.Replace(e_ToList, ";", ",");
                e_recipients = Regex.Split(e_ToList, ",");

                foreach (string rString in e_recipients)
                {
                    oRecips.Add(rString);
                }

                // Send.
                oMsg.Send();
                // Clean up.
                oRecips = null;
                oMsg    = null;
                oApp    = null;
            }//end of try block
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            } //end of catch
        }     //end of Email Method