0 votes
by (170 points)


I'm just wondering if Smtp.SendAsync is thread-safe?
For example in a windows service, can I do Connect/Login in startup of the windows service (or when first used), and then resuse the same Smtp object until the service stops?

That is: multiple threads may call Smtp.SendAsync simultaniously on the same Smtp object instance!

If so, is it recommeded to reuse the Smtp object in such scenarios?


Applies to: Rebex Secure Mail

1 Answer

0 votes
by (138k points)
selected by
Best answer

All Smtp methods are thread-safe in the sense that they fail if called while another method is in progress.

Reusing the same Smtp session is possible (and useful if you need to send more messages through one SMTP server), but you have to keep track of whether a method is currently active on a specific Smtp instance yourself.

However, please note that when connected to third-party SMTP servers, keeping connections idle unnecessarily (until the service stops or until they fail) would not be a good practice.