Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This coding run successfully and show mail send successfully, but mail not found in inbox.

Here I can't understand username & password logic because I gave it
Gmail account username, password anything else(Wrong userid,password)
then it run successfully so what give the username and password
or what can I changes for backend setting for send mail through my Gmail account?


C#
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net.Mail;

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


        SmtpClient smtp = new SmtpClient("192.168.1.2",Convert.ToInt32(25));
        System.Net.NetworkCredential cre = new System.Net.NetworkCredential("uamrit@gmail.com", "password");
        smtp.Credentials = cre;
        MailMessage message = new MailMessage();
        message.To.Add(new MailAddress("uamrit@gmail.com"));
        message.IsBodyHtml = true;
        message.Body = "<html><head><body><p> this is Demo for sending mail. </p></body></head></html>";
        message.Subject = ("response from the web sitre");
        message.From = new MailAddress("uamrit@gmail.com");



        try
        {
            smtp.EnableSsl = false;
          
            smtp.UseDefaultCredentials =false ;
            smtp.Send(message);
            Response.Write("Your Email has been sent sucessfully -");

        }
        catch (Exception exc)
        {
            Response.Write("Send failure: " + exc.ToString());

        }
    }


in webconfig


XML
<mailsetting>
<smtp from="uamrit@gmail.com">
<network host="192.168.1.2" port="25" username="uamrit" password="password" />
</smtp>
</mailsetting>
Posted
Updated 30-Dec-10 18:39pm
v2

You need to provide proper SMTP Server and valid username and password to make the email work.

Refer this[^]


Mark it as answer if it is helpful
 
Share this answer
 
v3
add different user to whome you are sending mail.
and use smtp client as "Smtp.gmail.com"
 
Share this answer
 
v2
:thumbsup:I agree the above answer,The sendbox must open the SMTP Server.You can set it in Gmail mail.
 
Share this answer
 
v2
Comments
Venkatesh Mookkan 31-Dec-10 0:57am    
Above? There are two answers about? Which one?

You can Up-Vote them you approve.
Venkatesh Mookkan 31-Dec-10 1:04am    
Thank you
tanyangui 31-Dec-10 1:35am    
SmtpClient smtp = new SmtpClient("192.168.1.2",Convert.ToInt32(25));
yeal,you use the 25 port.you can have a try 465 or 587 instead. Search GOOGLE get the Gmail's default port
It can be because of various reasons. You need to look at them one by one.
Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>

If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
 
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