?
Solved

Email log

Posted on 2005-04-13
11
Medium Priority
?
317 Views
Last Modified: 2010-04-04



 Using Indy, I need to set up a routine to email a small text file (Board.txt) every hour. It needs to do it automatically from my app.
 Is this possible to do? If so, i will increase the points to 200 for an example using Indy.

sholmes
0
Comment
Question by:IElite
  • 6
  • 3
  • 2
11 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13773419
0
 

Author Comment

by:IElite
ID: 13773476
K, how about an example on how to use the function, with the capability of it sending itself every hour.

IELite
0
 
LVL 26

Accepted Solution

by:
Eddie Shipman earned 2000 total points
ID: 13773508
Try doing something like this in a timer OnTimer event. (Set it's interval to 3,600,000)

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  EmailFile('c:\Board.txt');
end;

procedure TForm1.EmailFile(AFileName: TFileName);
  //
  // Returns mime type of file based on extension
  //
  function GetMimeType
    ( AFilename:                 String
    ): String;
  const
    MimeTypes: array[0..11] of string = ('.gif','.jpg','.png', '.css', '.htm', 'html',
                                        '.asp', '.aspx', '.xml', '.js', '.txt', '.log');
  begin
    case StringToCaseSelect(LowerCase(ExtractFileExt(AFilename)), MimeTypes) of
    0:  // gif
      begin
        Result := 'image/gif';
      end;
    1:  // jpg
      begin
        Result := 'image/jpg';
      end;
    2:  // png
      begin
        Result := 'image/png';
      end;
    3:  // css
      begin
        Result := 'text/css';
      end;
    4, 5: // htm, html
      begin
        Result := 'text/html';
      end;
    6, 7, 10, 11: // asp, aspx, .txt, .log
      begin
        Result := 'text/plain';
      end;
    8: // xml
      begin
        Result := 'text/xml';
      end;
    9: // js
      begin
        Result := 'text/javascript';
      end;
    else
      begin
        Result := 'application/binary';
      end;
    end;
  end;
 
var
  idAttach: TidAttachment;
  idText1: TidText;
  idText2: TidText;
  p: TidMessageParts;
  slBody: TStringList;
begin
  p := idMessage1.MessageParts;
  slBody := TstringList.Create;
  try
    slBody.Text('Here is the file '+ AFileName);
    idText1 := TidText.Create(p, slBody);
    idText1.ContentType := 'text/html';
    idText2 := TidText.Create(p);
    idText2.ContentType := 'text/plain';
    idText2.Body.Text := '';
    idAttach := TidAttachment.Create(p, AFileName);
    idAttach.ContentType := GetMimeType(AFileName);
    idAttach.ContentDisposition := 'inline';
    idMessage1.Body.Assign(slBody);
    idAttach.DisplayName := ExtractFileName(AFileName);
    idMessage1.ContentType := 'multipart/mixed';
    idSMTP1.Connect;
    idSMTP1.Send(idMessage1);
  finally
    idSMTP1.Disconnect;
    slBody.Free;
  end;
end;

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 13773524
BTW, you must setup idSMPT1 with your login parameters.
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 13773527
I can't test this here as my smtp server won't let me use Indy.
0
 

Author Comment

by:IElite
ID: 13773550
K, i will test it and give it a shot....


IElite
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13773602
You mean you wanted code to drop a timer onto a form to call the sendemail function?

I think people are getting a little toooo lazy these days
0
 

Author Comment

by:IElite
ID: 13776522
Excuse me mikelittlewood......
0
 

Author Comment

by:IElite
ID: 13776546
mikelittlewood, aside from not knowing how to use the TTimer, i also did not know how to call your routine...
excuse me for being a novice.... ithought the idea here was to help - i could be wrong .....

IElite
0
 

Author Comment

by:IElite
ID: 13776573
As a matter of fact, this is the third rude response i have received from this form today (although it was different experts in different groups.).
I am not happy, and i am going to write admin and let them know that my money is getting used to pay for rude responses......

IELite
0
 

Author Comment

by:IElite
ID: 13776584
No, as a matter of fact, i think i will just stop my account.....

Thanks to all who have helped me in the past!

IELite
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

864 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