UrosVidojevic
asked on
Sending mail message without entering my host information
In one Delphi book (Marco Cantu - Delphi 6) I found an example about sending the simple mail message. But in this example it is neccessary to enter the following information: myHost, myUsername and myPassword. Is it possible to make program which will send message without requiring this data? For example, to get this data from Outlook. I would realy appreciate a code sample for this.
As far as I know, it should be enough with connecting to SMTP server and just sending mail.
I'm using a TLinkLabel componet which allows uses to initiate an email (eg. mailto:support@mysite.com)
If you visit Torry's at http://www.torry.net and do a quick search for "Link Label" you'll find a number of options, most of which are free with source.
mwbowman, does clicking on this TLinkLabel open mail client or web browser?
ZhaawZ
Yes!
The component I'm using is the TbsSkinLinkLabel from http://www.almdev.com, which is part of the "skin" interface I use for my applications. It has a URL property which can be used in either of my examples above, and when clicked will open the default mail or browser application automatically as required.
However, I have use similar free/shareware components before that do the exact same thing.
ASKER
I need a component which will send an message (generated by my program) to specified addresses. Does anybody knows anything about component which can do this job (without using Outlook)?
Do you have Indy components? If yes, there should be some component that works as SMTP client
I believe if you want to create and send the email from within your program you will have to know the server information, etc in order for it to work. Delphi has a TNPPOP3 component that will do the trick.
However my original TLinkLabel suggestion should work with *any* mail client and/or web browser, and as long as these are setup on the computer already, you don't have to know anything about.
What exactly are you trying to accomplish with this anyhow? It may help us to better understand you're requirements...
I believe TNPPOP3 is for receiving mail, not for sending.
ZhaawZ
You're correct. I think I should have said TNMSMTP.
:-)
You're correct. I think I should have said TNMSMTP.
:-)
ASKER
I am trying to make a game which will send the best score on my e-mail (it is important that player can't change that score, which is possible if I use Outlook to send it).
So, For example If score is 100 I need code which will send it to address someadress@somehost.com.
Subject is "Game Results".
So, For example If score is 100 I need code which will send it to address someadress@somehost.com.
Subject is "Game Results".
Do you have that TNMSMTP component?
ASKER
Yes, I have that component.
hi UrosVidojevic,
Maybe you have this already, I don't know.
The text that you mention in the opening Q, I copied a Delphi sample below from an earlier
edition (Mastering Delphi 4 by Marco Cantu) pg.1088.
With this program there is a direct connect to Outlook, so no need for a password. But I cannot hook the 'send' button within Outlook to a Delphi button. That you will have physically do it yourself when Outlook is up and running. If you are connected to the internet the email will be sent.
Delphi3
unit SendingMailToOutlookUnit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ShellApi, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
TransferToOutlook: TButton;
Close: TButton;
EditAddress: TEdit;
EditSubject: TEdit;
MailFrom: TLabel;
MailTo: TLabel;
MessageText: TLabel;
procedure CloseClick(Sender: TObject);
procedure TransferToOutlookClick(Sen der: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.TransferToOutlookCl ick(Sender : TObject);
var
StrMsg: string;
I: Integer;
begin //set the basic info
StrMsg := 'MailTo:' + EditAddress.Text + '?Subject= ' + EditSubject.Text + '&Body= ';
//Add first line
if Memo1.Lines.Count > 1 then
StrMsg := StrMsg + Memo1.Lines[0];
//add subsequent lines seperated by the new line symbol
for I := 1 to Memo1.Lines.Count - 1 do
StrMsg := StrMsg + '%0d%0a' + Memo1.Lines[i];
//send the message
ShellExecute(Handle, 'open', PChar(StrMsg), '', '', SW_SHOW);
end;
procedure TForm1.CloseClick(Sender: TObject);
begin
Application.Terminate;
end;
end.
the .dfm as text
object Form1: TForm1
Left = 192
Top = 120
Width = 424
Height = 272
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 120
TextHeight = 16
object MailFrom: TLabel
Left = 216
Top = 8
Width = 45
Height = 16
Caption = 'Subject'
end
object MailTo: TLabel
Left = 16
Top = 8
Width = 42
Height = 16
Caption = 'MailTo'
end
object MessageText: TLabel
Left = 16
Top = 48
Width = 83
Height = 16
Caption = 'MessageText'
end
object Memo1: TMemo
Left = 112
Top = 40
Width = 185
Height = 129
TabOrder = 0
end
object TransferToOutlook: TButton
Left = 24
Top = 192
Width = 169
Height = 25
Caption = 'TransferToOutlook'
TabOrder = 1
OnClick = TransferToOutlookClick
end
object Close: TButton
Left = 208
Top = 192
Width = 169
Height = 25
Caption = 'Close'
TabOrder = 2
OnClick = CloseClick
end
object EditAddress: TEdit
Left = 72
Top = 8
Width = 121
Height = 24
TabOrder = 3
end
object EditSubject: TEdit
Left = 280
Top = 8
Width = 121
Height = 24
TabOrder = 4
end
end
Maybe you have this already, I don't know.
The text that you mention in the opening Q, I copied a Delphi sample below from an earlier
edition (Mastering Delphi 4 by Marco Cantu) pg.1088.
With this program there is a direct connect to Outlook, so no need for a password. But I cannot hook the 'send' button within Outlook to a Delphi button. That you will have physically do it yourself when Outlook is up and running. If you are connected to the internet the email will be sent.
Delphi3
unit SendingMailToOutlookUnit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ShellApi, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
TransferToOutlook: TButton;
Close: TButton;
EditAddress: TEdit;
EditSubject: TEdit;
MailFrom: TLabel;
MailTo: TLabel;
MessageText: TLabel;
procedure CloseClick(Sender: TObject);
procedure TransferToOutlookClick(Sen
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.TransferToOutlookCl
var
StrMsg: string;
I: Integer;
begin //set the basic info
StrMsg := 'MailTo:' + EditAddress.Text + '?Subject= ' + EditSubject.Text + '&Body= ';
//Add first line
if Memo1.Lines.Count > 1 then
StrMsg := StrMsg + Memo1.Lines[0];
//add subsequent lines seperated by the new line symbol
for I := 1 to Memo1.Lines.Count - 1 do
StrMsg := StrMsg + '%0d%0a' + Memo1.Lines[i];
//send the message
ShellExecute(Handle, 'open', PChar(StrMsg), '', '', SW_SHOW);
end;
procedure TForm1.CloseClick(Sender: TObject);
begin
Application.Terminate;
end;
end.
the .dfm as text
object Form1: TForm1
Left = 192
Top = 120
Width = 424
Height = 272
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 120
TextHeight = 16
object MailFrom: TLabel
Left = 216
Top = 8
Width = 45
Height = 16
Caption = 'Subject'
end
object MailTo: TLabel
Left = 16
Top = 8
Width = 42
Height = 16
Caption = 'MailTo'
end
object MessageText: TLabel
Left = 16
Top = 48
Width = 83
Height = 16
Caption = 'MessageText'
end
object Memo1: TMemo
Left = 112
Top = 40
Width = 185
Height = 129
TabOrder = 0
end
object TransferToOutlook: TButton
Left = 24
Top = 192
Width = 169
Height = 25
Caption = 'TransferToOutlook'
TabOrder = 1
OnClick = TransferToOutlookClick
end
object Close: TButton
Left = 208
Top = 192
Width = 169
Height = 25
Caption = 'Close'
TabOrder = 2
OnClick = CloseClick
end
object EditAddress: TEdit
Left = 72
Top = 8
Width = 121
Height = 24
TabOrder = 3
end
object EditSubject: TEdit
Left = 280
Top = 8
Width = 121
Height = 24
TabOrder = 4
end
end
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.