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.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

.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 = '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

Sign In or Register to comment.