Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I want to save the SMTP CLient Setting in the Web Config and send my emails via a controller. So I use this code fragment
MailMessage message = new MailMessage("mail1@test.de", "from@example.de"); message.Subject = "Subject"; message.Body = EmailRenderer.Renderer("Reminder", modul); SmtpClient client = new SmtpClient("127.0.0.1", 25); client.Send(message);
I don't want to set my SmtpClient-Settings here. Is this possible? How can I retrieve the credentials from the web.config?
Thank you in advance, Nadine
The configuration documentation is here: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/smtp-element-network-settings
You just create a new SmtpClient and the settings will already be read.
SmtpClient
I just need to call an empty constructor, am I right?
SmtpClient client = new SmtpClient();
If you have configured the <smtp> element in your Web.config, then yes ;)
<smtp>
ok, thanks this was the question ;)
FYI, the SmtpClient is IDisposable. You may get some dropped emails unless you dispose of it properly. Here's one way of doing that:
IDisposable
using (var client = new SmtpClient()) { // Your code here. }
The using statement will dispose of the SmtpClient for you.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
send Email via Controller and get SMTP Client Settings
Hi,
I want to save the SMTP CLient Setting in the Web Config and send my emails via a controller. So I use this code fragment
I don't want to set my SmtpClient-Settings here. Is this possible? How can I retrieve the credentials from the web.config?
Thank you in advance, Nadine
The configuration documentation is here: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/smtp-element-network-settings
You just create a new
SmtpClient
and the settings will already be read.I just need to call an empty constructor, am I right?
If you have configured the
<smtp>
element in your Web.config, then yes ;)ok, thanks this was the question ;)
FYI, the
SmtpClient
isIDisposable
. You may get some dropped emails unless you dispose of it properly. Here's one way of doing that:The using statement will dispose of the
SmtpClient
for you.is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.