Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void TextBox7_TextChanged(object sender, EventArgs e)
{
    string gMailAccount = "[[[Email Removed]]]";
    string password = "[[[Password Removed]]]";
    string yes;
    TextBox21.Visible = true;
    Label26.Visible = true;

    Random val = new Random();
    int rno = val.Next(12345, 54321);
    ranno = Convert.ToString(rno);
    Label22.Text = ranno;

    RegisterStartupScript("msg", "<script>alert('Your Mail Verification Key is : " + ranno + "')</script>");

    password = "[[[Password Removed]]]";
    message = "<hr><br>Hello " + "<b>" + TextBox1.Text + " ! </b><br><br>" + "Your Mail Verification Key is : " + "" + ranno + "";
    to = TextBox7.Text;
    NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
    MailMessage msg = new MailMessage();
    msg.From = new MailAddress(gMailAccount);
    msg.To.Add(new MailAddress(to));
    msg.Subject = subject;
    msg.Body = message;
    msg.IsBodyHtml = true;

    try
    {
        SmtpClient client = new SmtpClient("smtp.gmail.com");
        client.EnableSsl = true;
        client.UseDefaultCredentials = false;
        client.Credentials = loginInfo;
        client.Send(msg);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
    }

    yes = "yes";
}
}

it is working in offline but not working online that menas secret key not recived to the mail

whenever entering mail text changed property will popup secret key and send to the mail but mail is not recive the secret key.


pls help me.

[Edit member="Tadit"]
Added pre tags.
Email ID and Password Removed.
[/Edit]
Posted
v4
Comments
Thanks7872 9-Sep-14 9:19am    
Not clear. Do you mean that you received the email but it doesn't have HTML content it was suppose to contain?
[no name] 9-Sep-14 9:27am    
What is the exception you are getting?

1 solution

I am not sure, but you are missing port.
C#
client.Port = 587; // Gmail works on this port

Follow my previous answer sending email to gmail from asp.net[^]. You will find full working code.
 
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