I'm trying to sending Email through my web application from Gmail
by using Sustem.Net.Mail.SmtpClient
My code is

string To = "doctor_ofvet@yahoo.com";
        string From = "doctorofvet@gmail.com";
        string Subject = "The Famous";
        string Body = "Hello World";
        SmtpClient Client = new SmtpClient();
        Client.Send(From, To, Subject, Body);

I put this code in the web.config file

<system.net>
		<mailSettings>
			<smtp>
				<network host="smtp.gmail.com" port="465" userName="Gmail Username" password="Password"/>
			</smtp>
		</mailSettings>
	</system.net>

but it did not success

can any one help me please

Hi there,

Last time I mailed with C#-code, it happened like this:

MailMessage mailMessage;
SmtpClient client;

mailMessage = new MailMessage();
client = new SmtpClient("relay.skynet.be"); //your mail-out server
mailMessage.To.Add("...@hotmail.com");
mailMessage.Subject = "...";
client.Send(mailMessage);

This was not in a web application but just a C#.NET windows application. I hope this helps you.

debugging would show wether your mail settings are being picked up for your new smtpclient. If not, it maybe better to set them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.