SMTP relay in case if message was sent to more the - WeOnlyDo Discussion board

SMTP relay in case if message was sent to more the (wodSmtpServer / wodPop3Server / wodImapServer)

by bkv, Friday, April 20, 2012, 00:31 (4386 days ago)

Hello WEONLYDO,
What is the best approach for message relay if it was sent to more than one recipient?
In you sample № 4. Only relays received messages you are using MailReceived event like:

Private Sub wodSmtpServer1_MailReceived(ByVal User As WODSMTPSERVERCOMLib.ISmtpUser, Action As WODSMTPSERVERCOMLib.SmtpActions)
PrintList *** Mail received from & User.HostName & ! Contents follows:
PrintList User.Message.Body
PrintList *** Adding message to be relayed to & User.Message.MailTo
wodSmtpServer1.Relays.Add User.Message
End Sub

But MailReceived event is raised only once, for all recipients, and message will be relayed to last recipient which is saved in User.Message.MailTo property.

How to relay to all recipients?

Thanks in advance.

Re: SMTP relay in case if message was sent to more

by wodDamir, Friday, April 20, 2012, 09:14 (4386 days ago) @ bkv

Hi,

Actually, although MailReceived is triggered once (single message is received), message will be relayed to all recepients in MailTo property.

Just make sure that each recepient is separated by CrLf.

Regards,
Damba

Re: SMTP relay in case if message was sent to more

by bkv, Friday, April 20, 2012, 09:56 (4386 days ago) @ wodDamir

Thanks,for reply.
Then question is the next. Lets say MailTo contains 4 addresses:
1) email1@gmail.com
2) email2@gmail.com
3) email1@hotmail.com
4) email2@hotmail.com

What SMTP server will be used to replay?
Will it detect that address 1 and 2 belong to gmail.com domain and address 3 and 4 belong to hotmail.com domain and split two two relays?

Re: SMTP relay in case if message was sent to more

by wodDamir, Friday, April 20, 2012, 10:09 (4386 days ago) @ bkv

Hi,

Unless SmartHost for the relay is specified, component will always try to use mail server of the recepient.

If you wish to specify which server to use, you'll need to create a new relay and specify the server you wish to use.

Regards,
Damba

Re: SMTP relay in case if message was sent to more

by bkv, Friday, April 20, 2012, 13:23 (4386 days ago) @ wodDamir

Ok, I have got another problem.
If one of the destination addresses is not correct, then whole relay failed. Message is not relayed to any destination;

Example: Message was send to three destinations. One of the, is not correct (e.g not existing email addres). I am relaying this message using SmtpRelay smtpRelay = smtpserver.Relays.Add(User.Message);
The RelayError event is raized and message is not relayed to other correct addresses.

Re: SMTP relay in case if message was sent to more

by wodDamir, Friday, April 20, 2012, 13:33 (4386 days ago) @ bkv

Hi,

Ok, but that's why the Error event was triggered. Why not simply useit to remove the problematic address from the relay object, and call it's Retry method?

Regards,
Damba

Re: SMTP relay in case if message was sent to more

by bkv, Friday, April 20, 2012, 13:41 (4386 days ago) @ wodDamir

I don`t know, thats why I am asking :)

But the problem is that in the Error event it is not possible to detect what exactly address caused problem.

Re: SMTP relay in case if message was sent to more

by wodDamir, Friday, April 20, 2012, 13:54 (4386 days ago) @ bkv

Hi,

Order of addresses is changed each time a relaying fails. You can use that to distinguish which one failed and remove it.

Regards,
Damba

Re: SMTP relay in case if message was sent to more

by bkv, Friday, April 20, 2012, 14:07 (4386 days ago) @ wodDamir

I just checked - order of addresses is not changes in Relay.MailTo property.
More than will it be optimal to try to relay whole message again?

Re: SMTP relay in case if message was sent to more

by wodDamir, Friday, April 20, 2012, 14:22 (4386 days ago) @ bkv

Hi,

Yes. However, if it failed once, it's probably going to fail again. In that case, make sure that you set RetryCount property so that you make sure that realaying isn't done indefinitely.

regards,
Damba