Skip to content

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

Description

@yandrapragada
  • 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions