0

I am able to send emails via below way with Yahoo emails. But my question is can i also make it a way that computer will use proxy while connecting yahoo servers ? I mean use proxy connection to connect yahoo smpt server. Is this possible ? thank you

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;
}

Alright this question is not same as this one : Sending mail through http proxy

That question specifically asks how to use proxy

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

In this case i want to use threads, proxies for each thread and from this each thread connect to yahoo smtp server with using http proxy to send email

thank you

Community
  • 1
  • 1
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342
  • @Lloyd nope not at all. i want software to use proxy while connecting yahoo smtp servers. – Furkan Gözükara Jun 11 '13 at 17:12
  • What do you mean by proxy? A web proxy would be used to either hide an IP address or to help cache results but SMTP doesn't work like this. If you want to relay the mail via another mail server then can't you point your code to the relay server and get the relay to forward all mail to Yahoo? – Lukos Jun 25 '13 at 10:34
  • @Lukos i mean http proxy. i want to use http proxy for sending email to yahoo smtp. – Furkan Gözükara Jun 29 '13 at 23:14
  • May be answer you are looking is available at https://stackoverflow.com/questions/19446001/send-smtp-mail-from-gmail-live-aol-or-yahoo-accounts-when-my-pc-is-connected-v/42719817#42719817 – Deepak Bhatia Jun 05 '17 at 12:19

1 Answers1

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

Update: System.Net.GlobalProxySelection.Select has been deprecated

If you use it you will get a warning:

This class has been deprecated. Please use WebRequest.DefaultWebProxy instead to access and set the global default proxy. Use 'null' instead of GetEmptyWebProxy. http://go.microsoft.com/fwlink/?linkid=14202

Use this instead:

WebRequest.DefaultWebProxy = new WebProxy(address,port);
Richard Sitze
  • 8,262
  • 3
  • 36
  • 48
Avram Tudor
  • 1,468
  • 12
  • 18
  • How will you use this in multi threading application ? – Furkan Gözükara Jun 22 '13 at 00:33
  • alright this won't work in my case because i need to work multi threading – Furkan Gözükara Jun 24 '13 at 13:16
  • 1
    This is deprecated in .NET 4.5 in favor of `WebRequest.Proxy` – Ben Collins Jun 25 '13 at 16:10
  • @BenCollins can you please answer my question. that pointed question not answering my question at all – Furkan Gözükara Jun 29 '13 at 23:17
  • 1
    @MonsterMMORPG I think your question has already been answered. The question linked at the top *is* the same question you're asking. There is no difference between "how to use proxy" and "how to use http proxy to connect to another mail server to send email." Adding threads also doesn't change the answer. Either instantiate a new `SmtpClient` object for each thread or use a `static` instance. – Ben Collins Jun 30 '13 at 03:20
  • @BenCollins i am asking this. Using yahoo smtp already itself a proxy. But i want to add additional proxy between. So how to do that ? – Furkan Gözükara Oct 03 '13 at 10:14