Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am developing an application in which I have to send e-mail.
I am able to send e-mail when I have direct internet connection, but I am provided with proxy in my LAN.
Though I have to send email.

Please help me in send mail via proxy server.

Note:
I use c#.net.

Here is a piece of code that I use:


    string msgSubject = txtSubject.Text.Trim();
    string FrommailId = txtFrom.Text.ToString();
    string TomailId = txtTo.Text.ToString();
    string mailPassword = "password";
    string mailServer = txtMailServer.Text.Trim();
    System.Net.Mail.MailMessage objMessage = new MailMessage();
    objMessage.To.Add(TomailId);//Set To address
    objMessage.From = new MailAddress(FrommailId, "From", System.Text.Encoding.UTF8);//Set  From address
    objMessage.Subject = msgSubject;//Set Subject
    objMessage.SubjectEncoding = System.Text.Encoding.UTF8;
    objMessage.Body = txtMessage.Text.Trim();
    objMessage.BodyEncoding = System.Text.Encoding.UTF8;
    objMessage.IsBodyHtml = false;
    objMessage.Priority = MailPriority.High;

    SmtpClient client = new SmtpClient();
    client.Credentials = new System.Net.NetworkCredential(FrommailId, mailPassword);//Set UserName and Password for Network authendication
    client.Port = Convert.ToInt32(txtPortNo.Text.Trim());//Port for sending mail
    client.Host = mailServer;//587 For smtp.gmail.com
    client.EnableSsl = true;

client.Send(objMessage);


[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
Posted
Updated 2-Mar-11 21:48pm
v3
Comments
Dalek Dave 3-Mar-11 3:48am    
Edited for Grammar and Readability.

1 solution

 
Share this answer
 
Comments
JohnBrittoJ 3-Mar-11 3:47am    
Thank you sir. I am not able to give reference to Atp.Net namespace. Please help me in this issue.
Dalek Dave 3-Mar-11 3:48am    
Good Links.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900