如何从附件中的Gmail帐户撤消电子邮件 [英] How To Retreive E-Mail from Gmail account With Attachment

查看:91
本文介绍了如何从附件中的Gmail帐户撤消电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我想以编程方式连接(使用c#)到Gmail,以便通过附件检索电子邮件详细信息。

成功连接后,如何从Gmail逐个打开电子邮件并检查邮件是否包含附件,然后以编程方式下载此附件并保存在本地计算机中。



< b> 1)我将如何做到这一点?

2)如果有任何参考代码可以发送给我?





这是我的示例代码,

Hello,
I want to programmatic-ally connect(using c#) to Gmail for retrieving e-mails details with their attachment.
After successfully connected, how to open one by one email from Gmail and checking if mail contain attachment then download this attachment programmatic-ally and save in local machine.

1)How I will do this?
2)If any reference code available please send to me?


here is my sample code ,

using Microsoft.Office.Interop.Outlook;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MailApplication
{
    class Program
    {
        static void Main(string[] args)
        {
       //     Microsoft.Office.Interop.Outlook.MAPIFolder inbox =
       //    Application.ActiveExplorer().Session.GetDefaultFolder
       //(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

       //     Microsoft.Office.Interop.Outlook.Items unreadItems = inbox.
       //         Items.Restrict("[Unread]=true");

       //     MessageBox.Show(
       //         string.Format("Unread items in Inbox = {0}", unreadItems.Count));


            SmtPop.POP3Client pop = new SmtPop.POP3Client();

            pop.Open("pop.gmail.com",995, "abc@gmail.com", "abdre@345");
            
           
            // Get message list from POP server
            
            SmtPop.POPMessageId[] messages = pop.GetMailList();
            
            if (messages != null)
            {

                // Walk attachment list
                foreach (SmtPop.POPMessageId id in messages)
                {
                    SmtPop.POPReader reader = pop.GetMailReader(id);
                    SmtPop.MimeMessage msg = new SmtPop.MimeMessage();

                    // Read message
                    msg.Read(reader);
                    if (msg.AddressFrom != null)
                    {
                        String from = msg.AddressFrom[0].Name;
                        Console.WriteLine("from: " + from);
                    }
                    if (msg.Subject != null)
                    {
                        String subject = msg.Subject;
                        Console.WriteLine("subject: " + subject);
                    }
                    if (msg.Body != null)
                    {
                        String body = msg.Body;
                        Console.WriteLine("body: " + body);
                    }
                    //string attach1 = Convert.ToString(msg.Attachments);
                    //Console.WriteLine(attach1);
                    if (msg.Attachments != null )
                    {
                        // Do something with first attachment
                        SmtPop.MimeAttachment attach = msg.Attachments[0];
                       
                        if (attach.Filename == "")
                        {
                            // Read data from attachment
                            Byte[] b = Convert.FromBase64String(attach.Body);
                            System.IO.MemoryStream mem = new System.IO.MemoryStream(b, false);

                            //BinaryFormatter f = new BinaryFormatter();
                            // DataClass data= (DataClass)f.Deserialize(mem); 
                            mem.Close();
                        }

                        // Delete message
                        // pop.Dele(id.Id);
                    }
                }
            }
            pop.Quit();
        }
    }
}



谢谢,

Nitin

推荐答案

参见从G-Mail获取电子邮件 [ ^ ]。


这篇关于如何从附件中的Gmail帐户撤消电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆