New on LowEndTalk? Please Register and read our Community Rules.
.NET equivalent of PHPMailer
Hey everyone
What would be the .NET (C#) equivalent of the following PHPMailer code:
$mailServerType = 'smtp';
//IF $mailServerType = 'smtp'
$smtp_server = 'example.mymailcheap.com';
$smtp_user = '[email protected]';
$smtp_pw = 'UserPassword';
$smtp_port = 587;
$smtp_security = 'tls';
The following code is rejected by mail server as "Transaction failed. The server response was: 5.7.1 Client host rejected: Access denied"
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "example.mymailcheap.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "UserPassword");
MailMessage mm = new MailMessage("[email protected]", "[email protected]", "test", "test");
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.Send(mm);
I would guess the EnableSsl has to be changed to TLS or something equivalent. Server uses STARTTLS. Unfortunately I have no experience in .NET and appreciate any help!
Thanks and Best Regards,
Pavin Joseph.
Comments
Try some library. Use NuGet package manager to download it.
This one looks promising: https://www.nuget.org/packages/OpaqueMail/
Here is the link for the SMTP tutorial: https://github.com/bertjohnson/OpaqueMail/wiki/OpaqueMail-Library-Tutorial#smtp
Also note: some packages on NuGet are not free, this one though is MIT licensed.
The OpaqueMail library looks easy to use, esp. the SMTP. Hope it works!