Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Downloading email attachments

Posted on 2016-09-13
2
Medium Priority
?
126 Views
Last Modified: 2016-09-26
How do I download email attachments from my own WebSite's emails via Delphi.
0
Comment
Question by:Allan_Fernandes
2 Comments
 
LVL 28

Accepted Solution

by:
Sinisa Vuk earned 2000 total points
ID: 41796956
I don't want to re-invent a wheel - so here is a newsgroup thread how receiving mail attachment could be accomplished with Indy components..Basically, there is Indy TIdAttachment component which do most part...
0
 

Author Comment

by:Allan_Fernandes
ID: 41808259
Have tried the code, made some changes too.  I get the all messages successfully.
Problem is that the attachment filenames are blank. Even If I save it with, say 'abc.csv',  then 0 bytes file is created.

procedure TForm1.btn_SaveattachmentsClick(Sender: TObject);
var
   TheUID,fName: string;
   TheMsg: TIdMessage;
   nMsgPartsCount: integer;
begin
  TheUID := StringGrid1.Cells[1, StringGrid1.Selection.Top];

  try
    TheMsg := TIdMessage.Create(nil);

    TheImap.UIDRetrieveStructure(TheUID,TheMsg);

    for nMsgPartsCount := 0 to TheMsg.MessageParts.Count-1 do
    begin
      if TheMsg.MessageParts[nMsgPartsCount] is TIdAttachment then
      begin
        if TheMsg.MessageParts[nMsgPartsCount] is TIdAttachmentFile then
        begin
          fName := TIdAttachmentFile(TheMsg.MessageParts.Items[nMsgPartsCount]).Filename;
          if (fName <> '') then
          begin
            fName := ExtractFilePath(Application.exename)+'download\' + fName;
            TIdAttachmentFile(TheMsg.MessageParts.Items[nMsgPartsCount]).SaveToFile(fName);
            ShowMessage('Attachment saved '+fName);
          end;
        end
        else
          ShowMessage('Attachment ignored - Not recognised as a file');
      end;
    end;
  finally
    TheMsg.Destroy;
  end;
end;

Open in new window

0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question