从 GMail 的“已发送邮件"中获取电子邮件标题文件夹 [英] Get email headers from GMail's "Sent items" folder

查看:26
本文介绍了从 GMail 的“已发送邮件"中获取电子邮件标题文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序通过 GMail 向联系人发送电子邮件.通常这很有效,但我们注意到有时我的程序认为"它发送的电子邮件实际上并没有到达 Gmail,更不用说到达联系人了.我认为我可以在程序中添加一个检查,该检查访问 Gmail已发送邮件"文件夹以查看每封电子邮件是否确实已发送.

My program sends emails to contacts via GMail. Normally this works very well but we have noticed that sometimes an email which my program "thinks" it has sent doesn't actually arrive at Gmail, let alone arrive at the contacts. I thought that I might be able to add to the program a check which accesses the Gmail "sent items" folder to see whether each email has indeed been sent.

我有一些使用 TIdPOP3 组件的代码,但这会从收件箱中下载标题,而不是从已发送的项目中下载.我的问题是,如何访问已发送邮件文件夹中的标题?

I have some code using the TIdPOP3 component but this downloads headers from the Inbox, not from sent items. My question is, how can I access the headers in the sent items folder?

以下是我正在使用的代码.它只是测试代码,所以没有任何 try/finally 块等.

Following is the code that I am using. It's only test code so there aren't any try/finally blocks, etc.

 with pop do
  begin
   host:= 'pop.gmail.com';
   username:= 'someone@gmail.com';
   password:= .....;
   Port:= 995;
   Connect;
   if connected then 
    with i:= checkmessages downto 1 do
     begin
      msg.clear;   // msg is of type TIdMessage
      if retrieve (i, msg)
       then listbox1.items.add (msg.subject)
     end;
   disconnect
  end;

推荐答案

要获取与已发送项目相关的信息,您可以使用 Gmail imap_extensionsTIdIMAP4 组件.

To get the info related to the Sent Items you can use the Gmail imap_extensions and the TIdIMAP4 component.

试试这个示例

{$APPTYPE CONSOLE}


uses
  Classes,
  SysUtils,
  IdIMAP4,
  IdSSLOpenSSL,
  IdMessageCollection,
  IdExplicitTLSClientServerBase;

procedure GetSentItems;
var
  LIdIMAP4: TIdIMAP4;
  LIdSSLIOHandlerSocketOpenSSL : TIdSSLIOHandlerSocketOpenSSL;
  AMailBoxList: TStrings;
  AMsgList: TIdMessageCollection;
  i: integer;
begin
  LIdIMAP4 := TIdIMAP4.Create(nil);
  try
    LIdSSLIOHandlerSocketOpenSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    try
      LIdSSLIOHandlerSocketOpenSSL.SSLOptions.Method := sslvSSLv3;
      LIdIMAP4.IOHandler := LIdSSLIOHandlerSocketOpenSSL;
      LIdIMAP4.Host := 'imap.gmail.com';
      LIdIMAP4.Port := 993;
      LIdIMAP4.UseTLS := utUseImplicitTLS;
      LIdIMAP4.Username := 'user';
      LIdIMAP4.Password := 'password';
      LIdIMAP4.Connect;
      try
        //list the mail boxes 
        AMailBoxList:=TStringList.Create;
        try
        if LIdIMAP4.ListSubscribedMailBoxes(AMailBoxList) then
         Writeln(AMailBoxList.Text);
        finally
          AMailBoxList.Free;
        end;

        AMsgList:=TIdMessageCollection.Create(TIdMessageItem);
        try
        if LIdIMAP4.SelectMailBox('[Gmail]/Enviados') then //This folder name is localizated in english use [Gmail]/Sent Mail
          if LIdIMAP4.MailBox.TotalMsgs>0 then
            if LIdIMAP4.UIDRetrieveAllEnvelopes(AMsgList) then
             for i := 0 to AMsgList.Count-1 do
             begin
               //do your work here
               Writeln(AMsgList[i].Subject); //list the subject of the sent items
             end;
        finally
          AMsgList.Free;
        end;
      finally
        LIdIMAP4.Disconnect;
      end;
    finally
      LIdSSLIOHandlerSocketOpenSSL.Free;
    end;
  finally
    LIdIMAP4.Free;
  end;
end;



begin
  try
   GetSentItems;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  readln;
end.

这篇关于从 GMail 的“已发送邮件"中获取电子邮件标题文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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