I am trying to send an email using C# on a Windows 2016 server, running IIS 10. I installed IIS SMTP and it can send out messages using both Telnet and the windows pickup service.
Now I am using a C# webservice to send an email out. At first I tried to use SmtpDeliveryMethod.Network like this:
MailMessage mail = new MailMessage(mailFrom, mailTo);
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "localhost";
however that resulted in this error: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25
So as the pickup service of the IIS SMTP (on C:\\inetpub\\mailroot\\Pickup) is working I thought it would be best to just start using the pickup service.
Using this code:
MailMessage mail = new MailMessage(mailFrom, mailTo);
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
However this results in a Cannot get IIS pickup directory error.
So in IIS Services manager under SMTP I check the bullet at "Store e-mail in pickup directory:" And added C:\\inetpub\\mailroot\\Pickup in the text field.
This didn't work however. So I also changed the web.config and added these lines:
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\inetpub\mailroot\Pickup" />
</smtp>
</mailSettings>
</system.net>
This however didn't do the trick either. This will result in the following error:
Failure sending mail. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\inetpub\mailroot\Pickup\bb3fc5af-e213-43d3-af47-cb2836de78c3.eml'.
I still get the same error and don't know how to fix this.
Could you please help out?
Best regards
I couldn't get it to work. Eventually I just brought everything back to it origin and started over.
It works now, but what it is exactly I don't know for sure.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.