开发者

my send mail not found in inbox

i want to send mail in asp.net form here is my coding

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();
  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 = true;
    smtp.Send(message);
    Response.Write("Your Email has been sent sucessfully -");
  }
  catch (Exception exc)
  {
    Response.Write("Send failure: " + exc.ToString());
  }
}

in web.config

<system.net>
 <mailSettings>
  <smtp from="uamrit@gmail.com">
   <network host="192.168.1.299" port="25" userName="uamrit" password="*****"/>
  </smtp>
 </mailSettings>
</system.net>

this show mail send successfully but when we check my gmail account there no one mail for me why this happen. what the procedure to send mail plz send me full coding


There can be multiple reasons.Did you check your SPAM inbox? Also I see that you are pretending to send an email from GMAIL account through another server and I am sure GMAIL will not like it and migh blacklist your email address.

If you are planning to use GMAIL then why not use GMAIL SMTP settings?


In your config, you define a user name and password - yet, in your code, you specify

smtp.UseDefaultCredentials = true;

You need to decide which one to use - default credentials, or the username/password in the config?

I would think if you define a username/password in your config, you don't want to override that in your code by specifying UseDefaultCredentials = true...

If that doesn't solve you problems, I would try to specify the SMTP mail to go to a directory of your choosing, and see if the mails (stored as *.eml files in that directory) are really created at all. To do so, use this config:

<system.net>
 <mailSettings>
  <smtp from="uamrit@gmail.com" deliveryMethod="specifiedPickupDirectory">
     <specifiedPickupDirectory>C:\temp\mails</specifiedPickupDirectory>
  </smtp>
 </mailSettings>
</system.net>

You need to make sure the directory defined does already exist, though!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜