myloveCc/NETCore.MailKit

Proxy Protocol Exception : Failed to Connect to smtp.mailtrap.io:2525

yandrapragada opened this issue · 0 comments

  • OS: Windows
  • .NET Framework: .Net 6
  • Netcore.MailKit Version: 2.1.0

Untitled

I am trying to send mail using the Netcore.MailKit but always getting Proxy protocol exception.

C# code

 public void send(string to, string subject, string html)
        {
            // create message
            var from = "no_reply@myemail.com";
            var email = new MimeMessage();
            email.From.Add(MailboxAddress.Parse(from));
            email.To.Add(MailboxAddress.Parse(to));
            email.Subject = subject;
            email.Body = new TextPart(TextFormat.Html) { Text = html };

            // send email
            
            using (var SMTP = new SmtpClient())
            {
                SMTP.ProxyClient = new HttpProxyClient("10.44.1.234", 3128);
                SMTP.ServerCertificateValidationCallback = (s, c, h, e) => true;
                SMTP.Timeout = -1;
                SMTP.Connect("smtp.mailtrap.io",2525);
                SMTP.Authenticate("my_username", "my_password");
                SMTP.Send(email);
                SMTP.Disconnect(true);
            }
        }

My request has go through proxy for DNS resolution. I have added the proxy and used my credentials to send mails but failed to send .
I have even tried
SMTP.Connect("smtp.mailtrap.io",0,SecureSocketOptions.Auto);
SMTP.Connect("smtp.mailtrap.io",0,SecureSocketOptions.SslOnConnect);
SMTP.Connect("smtp.mailtrap.io",25,SecureSocketOptions.StartTls);

but could not get out of this error.