In order to send mail using a gmail address this can be used:
In Web.config
<system.net> <mailSettings> <smtp from="myemail@gmail.com" deliveryMethod="Network"> <network defaultCredentials="true" host="smtp.gmail.com" port="587" enableSsl="true" /> </smtp> </mailSettings> </system.net> |
And then in the code (in this case C# is used)
SmtpClient smtpClient = new SmtpClient(); smtpClient.UseDefaultCredentials = true; //reads the settings from web.config smtpClient.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "mypassword"); //and then send the message smtpClient.Send(mailMessage); |
Or if you don’t wish to save any settings in web.config
string host = "smtp.gmail.com"; int port = 587; SmtpClient smtpClient = new SmtpClient(host, port); smtpClient.UseDefaultCredentials = false; smtpClient.EnableSsl = true; smtpClient.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "mypassword"); //and then send the message contained in mailMessage smtpClient.Send(mailMessage); |
SmtClient at msdn
It might also be interesting to read up on mailmessage