Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
message.ISBodyHtml = true;
SmtpClient client = new SmtpClient("smpt.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("sprudhviraj17@gmail.com", "prudhviraj");
client.Send(message);



from the above code its showing message does not exist in the current context

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage(To.Text, From.Text, Subject.Text, Body.Text);
message.ISBodyHtml = true;
SmtpClient client = new SmtpClient("smpt.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("sprudhviraj17@gmail.com", "prudhviraj");
client.Send(message);
Status.Text = "mail sent sucessfully";
}
catch(Exception ex)
{
Status.Text = ex.StackTrace;

}




Status.Text = "Send is clicked";
}
}
Posted
Updated 12-May-17 1:09am
Comments
Richard Deeming 12-May-17 8:35am    
If those are your real GMail credentials that you've just posted to a public forum, then you URGENTLY need to change your password, before your account is hijacked.

And this time, choose a strong password. Or better yet, use a password manager and let that generate a strong password for you.

You declared a variable with name "mail", not "message". This is a really very basic thing, did you even try to solve it by yourself?

Also, I recommend you to remove your email credentials from your question.
 
Share this answer
 
Try:
MailMessage message = new MailMessage(To.Text, From.Text, Subject.Text, Body.Text);
message.ISBodyHtml = true;
SmtpClient client = new SmtpClient("smpt.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("sprudhviraj17@gmail.com", "prudhviraj");
client.Send(message);
Status.Text = "mail sent sucessfully";


Best regards
Espen Harlinn
 
Share this answer
 
It should be
C#
client.Send(mail);

because your mail message object is mail not message.
 
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