Click here to Skip to main content
15,887,340 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Sir,
I wanted to send email in in asp .net 3.5 with C#. I have implemented the following code:
C#
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
        mail.To.Add("taannmay@gmail.com");
        mail.To.Add("toemail@yahoo.com");
        mail.From = new MailAddress("frmemail@gmail.com");
        mail.Subject = "Email using Gmail";

        string Body = "Hi, this mail is to test sending mail" +
                      "using Gmail in ASP.NET";
        mail.Body = Body;

        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
        smtp.Credentials = new System.Net.NetworkCredential
             ("myemailID@gmail.com", "mypassword");
        //Or your Smtp Email ID and Password
        smtp.EnableSsl = true;
        smtp.Send(mail);

but the error which I am getting is:

System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 74.125.53.109:25
Posted
Updated 18-Feb-11 5:07am
v2

Port 25 is apparently blocked for either that server, or for the domain it's on.

You're going to have to negotiate with the IT nazis.
 
Share this answer
 
Following piece of code wil let u send email using google server

just replace network credentials with your google username, password,


C#
            MailAddress mafrom = new MailAddress("mani@abc.com");
            MailAddress mato = new MailAddress("dontumindit@yahoo.com");
            MailMessage mymsg = new MailMessage(mafrom, mato);

//body of the email
            mymsg.Subject = "hy";
            mymsg.Body = "How are You";

//SMTP Settings, i have written for google, you may write your SMTP server
            SmtpClient smptc = new SmtpClient("smtp.gmail.com", 587);
            smptc.UseDefaultCredentials = false;
            smptc.EnableSsl = true;

//Your username, password for SMTP server            
            smptc.Credentials = new NetworkCredential("username", "password");
            smptc.Send(mymsg);


Before providing Credentials, You need to set UserDefaultCredentials to false.

I have tested this code and used it to send mails, Even i have tried sending emails with attachments, and it works.

Have Nice Time.
 
Share this answer
 
Sir,
I want full source code email and doc file upload in asp.net using c#.
 
Share this answer
 

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