Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email through Delphi

I have never worked with Delphi (my girlfriend have some experience), but there is a small tool that I want to make and I think it should be made on Delphi. After hours of searching and testing we found only this guide (http://delphi.about.com/od/indy/a/email-send-indy.htm) which doesn't work, it gives a huge error when pressing the Send email button.

I am trying to make a tool that will be distributed with my game and will allow the user to send me an email (to my Gmail) in case of a problem or for feedback. He will enter his email, attach a screenshot and fill in a comment box, doesn't need to have something else. Any help will be highly appreciated as I am stuck, thank you.

like image 957
Yordan Sirakov Avatar asked Jan 20 '26 18:01

Yordan Sirakov


2 Answers

Here's a simple routine to send an email. I guess you can modify it to fit your needs:

procedure SendImage(const Comment, AImage: String);
var
  SMTP: TIdSMTP;
  Msg: TIdMessage;
begin
  if not FileExists(AImage) then
    Exit;
  Msg := TIdMessage.Create(nil);
  try
    Msg.From.Address := '[email protected]';
    Msg.Recipients.EMailAddresses := '[email protected]';
    Msg.Body.Text := Comment;
    TIdAttachmentFile.Create(Msg.MessageParts, AImage);
    Msg.Subject := AImage;
    SMTP := TIdSMTP.Create(nil);
    try
      SMTP.Host := 'smtp.gmail.com';
      SMTP.Port := 25;
      SMTP.AuthType := satDefault;
      SMTP.Username := '[email protected]';
      SMTP.Password := '@#$%';
      SMTP.Connect;
      SMTP.Send(Msg);
    finally
      SMTP.Free;
    end;
  finally
    Msg.Free;
  end;
end;

PS: Note that you have to replace [email protected] with your own email address, and not the user's. You could include their email address in the body of the crash report.

like image 196
iMan Biglari Avatar answered Jan 23 '26 18:01

iMan Biglari


IMO, email is not going to work 100% of the time. You'll be lucky to get 80%. If you use your SMTP, firewalls and ISPs must permit it. If you use their existing email client, you rely on proper configuration. A typical scenario is that they use Gmail or Yahoo, and then you try to send something via "imap email already on system" and the user gets confronted with an old copy of Outlook Express or Windows Mail that they didn't even know they had, but it's "registered" with windows as the default email handler. This gets ugly. I recommend sending via HTTP to an app on your web page. A PHP script that records the info and image into a MySQL database. Actually, I recommend using a bug tracking database like Mantis or FogBugz (from our patron!). I'd check them out, and then if you like what they offer, it's fairly straightforward to submit reports via HTTP post (or email, etc.).

like image 27
Chris Thornton Avatar answered Jan 23 '26 19:01

Chris Thornton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!