Setting from email address in code

delphi package - automated exception handling
Post Reply
jimmellish
Posts: 4
Joined: Tue Jan 17, 2006 3:05 pm

Setting from email address in code

Post by jimmellish »

Is it possible to set the from email address in code ?

One of our clients has set up their outgoing email not to send if the from address is not recoginsed so I want to use a specific address and not allow the user to enter one.
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

uses madExcept;

MailFrom := 'test@test.com'; // madExcept 2.x
MESettings.MailFrom := 'test@test.com'; // madExcept 3.x
jimmellish
Posts: 4
Joined: Tue Jan 17, 2006 3:05 pm

Post by jimmellish »

I can't get this to work ! I am using version 3.0a.

If I allow the user to enter a from email address in the EmailEdit field on then ContactForm then everything is ok.

If I remove the EmailEdit field and use the code above then the email is not sent. I think (but not sure) that this is because the from address is blank.

I have madExcept set to 'act as a SMTP main client'.

The exception I am generating is not very complicated:

procedure TForm1.Button1Click(Sender: TObject);
begin
MESettings.MailFrom := 'fred@abc.co.uk';
raise Exception.Create ('Hello');
end;
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

What happens if you remove the whole ContactForm? I guess the ContactForm clears your MailFrom value. It's just a guess right now, though.
jimmellish
Posts: 4
Joined: Tue Jan 17, 2006 3:05 pm

Post by jimmellish »

If I remove the ContactForm then everything works ok.

However, I now need to set the from name in code since the users can't enter it in the ContactForm. How do I do this ?
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

The problem is the "OnAction" handler of the ContactForm. It fills MailFrom. So what you have to do is this:

(1) Either remove/replace the OnAction handler, then you can use the ContactForm again.
(2) Or create your own form to ask for the user name.
jimmellish
Posts: 4
Joined: Tue Jan 17, 2006 3:05 pm

Post by jimmellish »

I think I found an easier solution. Keep the contact form, enter the email address I want to use as the value of the EmailEdit field and set enabled to False.

This works for me since I want to use the same email address for any exception in the exe.
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Yeah, sounds fine.
Post Reply