I want to send email in C# via SMTP to different mail providers example Gmail, Yahoo, AOL, Msn, Live etc so that my code works fine if my computer is connected to internet via proxy or connected directly to internet. (Proxy is a forward proxy taking requests from an internal network and forwarding them to the Internet and I configure proxy in I.E. as)
.................................
I have code by which I can send SMTP mail if PC is not connected via proxy
public void SendMail(string senderId, string password, List<string> To, List<string> CC, List<string> BCC, string Subject, string Body, List<Attachment> Attachment)
{
SmtpClient SmtpServer = null;
string[] ss = senderId.Split('@');
string ServerName = ss[1].Substring(0, ss[1].IndexOf("."));
switch (ServerName.ToLower())
{
case "gmail":
SmtpServer = new SmtpClient("smtp.gmail.com");
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(senderId, password);
SmtpServer.EnableSsl = true;
break;
case "msn":
case "live":
case "hotmail":
case "outlook":
SmtpServer = new SmtpClient("smtp.live.com");
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential(senderId, password);
SmtpServer.EnableSsl = true;
break;
case "aol":
SmtpServer = new SmtpClient("smtp.aol.com");
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential(senderId, password);
SmtpServer.EnableSsl = true;
break;
case "yahoo":
case "ymail":
case "rocketmail":
case "yahoomail":
SmtpServer = new SmtpClient("smtp.mail.yahoo.com");
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential(senderId, password);
SmtpServer.EnableSsl = false;
break;
default:
break;
}
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage mail = new MailMessage();
mail.From = new MailAddress(senderId);
foreach (string item in To)
{
mail.To.Add(item);
}
foreach (string item in CC)
{
mail.CC.Add(item);
}
foreach (string item in BCC)
{
mail.Bcc.Add(item);
}
mail.Subject = Subject;
mail.Body = Body;
foreach (Attachment item in Attachment)
{
mail.Attachments.Add(item);
}
SmtpServer.Send(mail);
}
This is working perfectly fine but I want to send email when I am connected via proxy.
I have read so many posts like,
Sending Mail over proxy server
ASP.net SMTP Mail though Proxy
Is there .NET library for email sending via PROXY?
They all state it is not possible but while searching I found chilkat library, limilabs sample which allows user to send mail via proxies by configuring the proxy.
I have researched a lot, I have read SOCKS proxy, learnt how to send SMTP mail using raw sockets but I am unable to find solution something missing.
I will appreciate any ideas for some work that has been done before, if any one who faced the same problem or any ideas what I can do?
EDIT:- As I have already mentioned that, I have found samples using Chilkat and limilabs it means I do not want to use those and I am not allowed to use any third party dll