【问题标题】:Reading emails from gmail by subject按主题阅读来自 gmail 的电子邮件
【发布时间】:2014-01-29 12:44:38
【问题描述】:

我想从我的 gmail 阅读,我想搜索电子邮件主题(“主题”),它包含一个附件(照片),我想将照片作为图像并使用它。

我尝试使用 MailRepository 类,从这里开始: http://mailsystem.codeplex.com/

但它会读取我 gmail 中的所有电子邮件,并且程序卡住了。

我需要一种有效的方法来实现我的目的,

提前感谢

【问题讨论】:

    标签: c# email gmail attachment


    【解决方案1】:

    我发现了如何做到这一点:

    首先,需要添加一个名为:OpenPop 的引用

        public static byte[] GetUserImage(string image_name)
        {
            Pop3Client c = new Pop3Client();
    
            c.Connect("pop.gmail.com", 995, true);
            c.Authenticate("your gmail", "password");
            for (int i = c.GetMessageCount(); i >= 1; i--)
            {
                OpenPop.Mime.Message mess = c.GetMessage(i);
                if (mess.Headers.Subject.Equals(image_name))
                {
                   return mess.MessagePart.MessageParts[1].Body;//this to get attachment
                                                **OR:**
                   return Encoding.ASCII.GetString(mess.MessagePart.Body);//this to get text
                }
    
            }
            return null ;
        }
    

    【讨论】:

      猜你喜欢
      • 2022-08-17
      • 2014-01-25
      • 1970-01-01
      • 2020-07-21
      • 2023-02-04
      • 2021-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多