本地主机:28642表示对象引用未设置为对象的实例 [英] Local host : 28642 says object reference not set to an instance of an object

查看:57
本文介绍了本地主机:28642表示对象引用未设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从表单发送邮件时出现此错误消息。



本地主机:28642表示对象引用未设置为对象的实例



当我以一种形式调用邮件
时,相同的命令会以另一种形式运行。

Had this error message when I send a mail from a form.

local host : 28642 says object reference not set to an instance of an object

When I invoke the mail in one form
, however the same commands works in another form.

           EmailSubj = "Complaint Filed  ";
           EmailMsg  = Convert.ToString(txt_Comp_memo.Text);

           string[] emails = new string[] { txt_Email.Text, txt_Zemail.Text, txt_Bemail.Text };
           foreach (var email in emails)
           {
               if (!string.IsNullOrWhiteSpace(email))
                   SendEmail(email, EmailSubj, EmailMsg);



private void SendEmail(String ToEmail, String Subj, string Message)
   {
       try
       {
           //Reading sender Email credential from web.config file
           HostAdd = ConfigurationManager.AppSettings["Host"].ToString();
           FromEmailid = ConfigurationManager.AppSettings["FromMail"].ToString();
           Pass = ConfigurationManager.AppSettings["Password"].ToString();

           //creating the object of MailMessage
           MailMessage mailMessage = new MailMessage();

           mailMessage.From = new MailAddress(FromEmailid); //From Email Id
           mailMessage.Subject = Subj; //Subject of Email
           mailMessage.Body = Message; //body or message of Email
           mailMessage.IsBodyHtml = true;
           mailMessage.To.Add(new MailAddress(ToEmail)); //reciver's Email Id

           SmtpClient smtp = new SmtpClient(); // creating object of smptpclient
           smtp.Host = HostAdd; //host of emailaddress for example smtp.gmail.com etc

           //network and security related credentials

           smtp.EnableSsl = true;
           NetworkCredential NetworkCred = new NetworkCredential();
           NetworkCred.UserName = mailMessage.From.Address;
           NetworkCred.Password = Pass;
           smtp.UseDefaultCredentials = true;
           smtp.Credentials = NetworkCred;
           smtp.Port = 587;
           smtp.Send(mailMessage); //sending Email

           string error = "Message Sent successfully. Thank you..!!";

           ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('" + error + "');", true);

           txt_Comp_memo.Text = " ";
           txt_Email.Text = " ";
           txt_Zemail.Text = " ";
           txt_Bemail.Text = " ";


       }
       catch (Exception ex)
       {
           string error = ex.Message;
           ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('" + error + "');", true);
       }

       finally
       {

       }

   }

           }





我尝试了什么: < br $>


查看了我自己的代码并查找了解决问题的方法的错误消息。



What I have tried:

Reviewed my own codes and looked for the error message on ways to resolve the problem.

推荐答案

这个问题是每天询问,请在提问之前做基础研究。搜索错误消息,您将从许多线程中看到有关此错误的帖子缺少重要信息,您需要通过调试器对此进行调查。
This question is asked daily, please do basic research before asking a question. Search for the error message and you'll see from the many threads about this error that your post is lacking vital information, and that you need to investigate this via the debugger.


这篇关于本地主机:28642表示对象引用未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆