Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

.NET equivalent of PHPMailer
New on LowEndTalk? Please Register and read our Community Rules.

.NET equivalent of PHPMailer

mailcheapmailcheap Member, Host Rep

Hey everyone :)

What would be the .NET (C#) equivalent of the following PHPMailer code:

$mailServerType = 'smtp';
//IF $mailServerType = 'smtp'
$smtp_server = '';
$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 = "";
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;


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.


Sign In or Register to comment.