How to use an HTTP proxy when sending email through SmtpClient

I can send emails via Yahoo email. But my question is: can I also make the computer use a proxy server when connecting yahoo servers? I mean using a proxy connection to connect the yahoo smpt server. Is it possible? thank

public static bool func_SendEmail(string srFrom, string srSenderEmail, string srSenderEmailPw, 
        string srHtmlBody, string srTextBody, string srTitle, string srProxy)
{
    try
    {
        using (MailMessage message = new MailMessage(new MailAddress(srSenderEmail, srFrom), new MailAddress(srSenderEmail)))
        {
            message.ReplyTo = new MailAddress(srSenderEmail, srFrom);
            message.IsBodyHtml = false;
            message.Subject = srTitle;
            message.SubjectEncoding = System.Text.Encoding.UTF8;
            AlternateView textPart = AlternateView.CreateAlternateViewFromString(srTextBody, Encoding.UTF8, "text/plain");
            textPart.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
            message.AlternateViews.Add(textPart);
            AlternateView htmlPart = AlternateView.CreateAlternateViewFromString(srHtmlBody, Encoding.UTF8, "text/html");
            htmlPart.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
            message.AlternateViews.Add(htmlPart);
            message.BodyEncoding = Encoding.UTF8;
            using (SmtpClient oSmtp = new SmtpClient())
            {
                oSmtp.Host = "smtp.mail.yahoo.com";
                oSmtp.Credentials = new NetworkCredential(srSenderEmail, srSenderEmailPw);
                oSmtp.EnableSsl = false;
                oSmtp.Port = 587;
                oSmtp.Send(message);
            }
        }
    }
    catch
    {
        return false;
    }
    return true;
}

It’s good that this question is not like this one: Sending mail through http proxy

This question specifically asks how to use a proxy server.

My question, on the other hand, asks how to use http proxy to connect another mail server to send email

, yahoo smtp http proxy

0
1
System.Net.GlobalProxySelection.Select = new WebProxy(address,port);

: System.Net.GlobalProxySelection.Select

, :

. WebRequest.DefaultWebProxy - . 'null' GetEmptyWebProxy. http://go.microsoft.com/fwlink/?linkid=14202

:

WebRequest.DefaultWebProxy = new WebProxy(address,port);
+2

Source: https://habr.com/ru/post/1741211/


All Articles