zoukankan      html  css  js  c++  java
  • 收到邮件且自动发送到对方提供的邮箱

    终于出结果啦,下面是程序

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Office.Interop.Outlook;
    using System.Net.Mail;


    namespace dgx
    {
        class program
        {
            static string strHost = string.Empty;
            static string strAccount = string.Empty;
            static string strPwd = string.Empty;
            static string strFrom = string.Empty;

            static void Main()
            {
               
                ApplicationClass OutLookApp = new ApplicationClass();
                OutLookApp.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(OutLookApp_NewMailEx);
                Console.ReadLine();
            }

            static void OutLookApp_NewMailEx(string EntryIDCollection)
            {
                string y="";

                ApplicationClass d = new ApplicationClass();
                NameSpace outlookns = d.GetNamespace("MAPI");
                MAPIFolder mFolder = d.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
                MailItem newmail = (MailItem)outlookns.GetItemFromID(EntryIDCollection, mFolder.StoreID);                      
              
                string[] split = newmail.Body.Split(new char[] { ',' });           
                char[] dg = split [0].ToCharArray();
                Array.Reverse(dg);
              
                foreach (char dx in dg)
                {               
                  y+=dx;         
                }
               
                strHost = "mail.zhuangxiang.com";   //STMP服务器地址
                strAccount = "dengguoxing@zhuangxiang.com";       //SMTP服务帐号
                strPwd = "dengguoxing";       //SMTP服务密码
                strFrom = "dengguoxing@zhuangxiang.com";  //发送方邮件地址

                sendMail(newmail.Subject, "装箱大师授权文件",y );
               
            }


            static bool sendMail(string to, string title, string content)
            {
                SmtpClient _smtpClient = new SmtpClient();
                _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
                _smtpClient.Host = strHost; ;//指定SMTP服务器
                _smtpClient.Credentials = new System.Net.NetworkCredential(strAccount, strPwd);//用户名和密码

                MailMessage _mailMessage = new MailMessage(strFrom, to);
                _mailMessage.Subject = title;//主题
                _mailMessage.Body = content;//内容
                _mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
                _mailMessage.IsBodyHtml = true;//设置为HTML格式
                _mailMessage.Priority = MailPriority.High;//优先级

                try
                {
                    _smtpClient.Send(_mailMessage);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
    }


     

  • 相关阅读:
    EventBus详解
    Java BigDecimal使用
    StringFormate使用
    Sourcetree拉取推送问题
    Android下拉刷新控件android-Ultra-Pull-To-Refresh 使用
    SourceTree跳过Atlassian账号,免登陆,跳过初始设置
    Android Studio3.2新建项目gradle read time out
    底部导航栏使用BottomNavigationBar
    PopupWindow封装
    电脑连接真机,但是androidstudio不显示手机,ADB Interface黄色感叹号
  • 原文地址:https://www.cnblogs.com/bluewelkin/p/1282571.html
Copyright © 2011-2022 走看看