Solved

Downloading email attachments

Posted on 2016-09-13
2
105 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
Easy CSR creation in Exchange 2007,2010 and 2013
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

615 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