示例#1
0
        /// <summary>
        /// Adds an email to MS Outlook Outbox
        /// </summary>
        /// <param name="toValue">Email address of recipient</param>
        /// <param name="asunto">Email subject</param>
        /// <param name="cuerpo">Email body</param>
        public void addToOutBox(string toValue, string asunto, string cuerpo, List <string> archivosAdjuntos)
        {
            //creates a new MailItem object
            Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            oMailItem.To       = toValue;
            oMailItem.Subject  = asunto;
            oMailItem.HTMLBody = cuerpo;

            foreach (string adjunto in archivosAdjuntos)
            {
                oMailItem.Attachments.Add(adjunto);
            }
            //oMailItem.SaveSentMessageFolder = oOutboxFolder;

            Microsoft.Office.Interop.Outlook.Accounts accounts = oApp.Session.Accounts;

            foreach (Microsoft.Office.Interop.Outlook.Account account in accounts)
            {
                string address = account.SmtpAddress;
                if (address == _cuenta)
                {
                    oMailItem.SendUsingAccount = account;
                }
            }

            //uncomment this to also save this in your draft
            //oMailItem.Save();

            //adds it to the outbox
            oMailItem.Send();
        }
 private void SendMsg(string msgContent)
 {
     Microsoft.Office.Interop.Outlook.Application oApp      = new Microsoft.Office.Interop.Outlook.Application();
     Microsoft.Office.Interop.Outlook._MailItem   oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
     oMailItem.To      = OutlookBank.TO;
     oMailItem.Subject = OutlookBank.SUBJECT;
     oMailItem.Body    = msgContent;
     oMailItem.Display(false);
     oMailItem.Send();
 }
示例#3
0
        }       // enviar email

        private void email_Click(object sender, EventArgs e)
        {
            try
            {
                Microsoft.Office.Interop.Outlook.Application oApp      = new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook._MailItem   oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                oMailItem.To = "meter campo transportadora.email";

                oMailItem.HTMLBody = "Segue em anexo o pdf com os dados da encomenda. <br> Atentamente, AMD";

                //Add an attachment.
                String sDisplayName = "Encomenda";
                int    iPosition    = (int)oMailItem.Body.Length + 1;
                int    iAttachType  = (int)Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue;

                //now attached the file
                Microsoft.Office.Interop.Outlook.Attachment oAttach = oMailItem.Attachments.Add(@"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName);

                //Subject line
                oMailItem.Subject = "Encomenda AMD";

                // Add a recipient.
                Microsoft.Office.Interop.Outlook.Recipients oRecips = (Microsoft.Office.Interop.Outlook.Recipients)oMailItem.Recipients;

                // Change the recipient in the next line if necessary.
                Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add("meter o campo da transportadora.email");
                oRecip.Resolve();

                oMailItem.Display(true);

                // Send.
                oMailItem.Send();

                // Clean up.
                oRecip    = null;
                oRecips   = null;
                oMailItem = null;
                oApp      = null;
            }


            catch (Exception ex)
            {
                MessageBox.Show("Não conseguimos carregar a aplicação de email. Por favor tente mais tarde.");
            }
        }