Click here to Skip to main content
11,718,589 members (84,581 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# email SMTP proxy mailing , +
Hi I want to send mail with ASP.NET,
but I want to send email through proxy server,
So how should I edit the code below to send it through a proxy server?

Thanks

MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient(ConfigurationManager.AppSettings["MailServer"]);
                mail.From = new MailAddress(ConfigurationManager.AppSettings["MailAccount"]);
                mail.To.Add(toAddres);
                mail.CC.Add(new MailAddress(ccAddress));
                mail.Subject = subject;
                mail.Body = content;
                mail.IsBodyHtml = true;
                SmtpServer.Port = ConfigurationManager.AppSettings["MailPort"] == null ? 587 : int.Parse(ConfigurationManager.AppSettings["MailPort"]);
                SmtpServer.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["MailUserName"], ConfigurationManager.AppSettings["MailPassword"]);
                SmtpServer.EnableSsl = false;
                
                SmtpServer.Send(mail);
Posted 7-Nov-12 0:43am
kubi081942

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can create a Method to send the mail through proxy...

MailAddress from = new MailAddress("from@mailserver.com");
MailAddress to = new MailAddress("to@mailserver.com");
 
MailMessage mm = new MailMessage(from, to);
mm.Subject = "Subject"
mm.Body = "Body";
 
SmtpClient client = new SmtpClient("proxy.mailserver.com", 8080);
client.Credentials = new System.Net.NetworkCredential("from@mailserver.com", "password");
 
client.Send(mm);

There is no need to incorporate it into your web.config at all
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 651
1 OriginalGriff 210
2 F-ES Sitecore 185
3 Jochen Arndt 160
4 Maciej Los 130
0 OriginalGriff 535
1 Maciej Los 529
2 Richard MacCutchan 440
3 CHill60 415
4 F-ES Sitecore 415


Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100