user1769184
user1769184

Reputation: 1621

Sending mail with INDY/DELPHI , modify values without restrictions

I'm sending E Mails with INDY 10 components with the following code :

  try
    MyNewIndyMessage.From.Address := edFrom.Text;
    MyNewIndyMessage.Recipients.EMailAddresses := edTo.Text;
    MyNewIndyMessage.CCList.EMailAddresses := edCC.Text;
    MyNewIndyMessage.BCCList.EMailAddresses := edBCC.Text;
    MyNewIndyMessage.Subject := edSubject.Text;
    MyNewIndyMessage.Body := edContent.Lines;
    MyIndySMTP.Send(MyNewIndyMessage);
  finally
    MyIndySMTP.Disconnect;
  end;

Indy smtp requests me to enter a valid organisation in the Message.from.address like "[email protected]" , I wouöld like to enter here and arbitray string like "This mail is urgent to read". Can I bypass such check done in my INDY SMTP components ?

Upvotes: 2

Views: 972

Answers (1)

jachguate
jachguate

Reputation: 17203

According to the Internet Message Format specification (RFC 2822), the From field must contain a valid mailbox, which normally is (section 3.4):

Normally, a mailbox is comprised of two parts: (1) an optional display name that indicates the name of the recipient (which could be a person or a system) that could be displayed to the user of a mail application, and (2) an addr-spec address enclosed in angle brackets ("<" and ">"). There is also an alternate simple form of a mailbox where the addr-spec address appears alone, without the recipient's name or the angle brackets.

An example of this may be like this:

John Doe <[email protected]>

As implied, mail clients usually display the (optional) name attribute if present, and the address itself if a name is not present.

In INDY terms, the TIdEMailAddressItem have three properties, which are always in sync:

  • Address is the address-spec part of the mailbox, for example: [email protected]
  • Name is the name part of the mailbox, for example: John Doe
  • Text have both parts, for example: John Doe <[email protected]>

You can change one of that and the others will reflect the same changes.

So, you can do what you want by setting the Text property directly, like this:

MyNewIndyMessage.From.Text := 'This mail is urgent to read <[email protected]>';

Or you may want to set each one separately:

MyNewIndyMessage.From.Address := '[email protected]';
MyNewIndyMessage.From.Name := 'This mail is urgent to read';

All this said, you may want to use that name as the subject (along with some more info), and not really as the name, but that's up to you.

Upvotes: 5

Related Questions