我在发送电子邮件时收到错误“指定的字符串不是电子邮件地址所需的格式。”请帮助我 [英] I am getting error while sending email "The specified string is not in the form required for an e-mail address." plz help me

查看:103
本文介绍了我在发送电子邮件时收到错误“指定的字符串不是电子邮件地址所需的格式。”请帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发送电子邮件时收到错误指定的字符串不是电子邮件地址所需的格式。 PLZ帮帮我



下面是代码



I am getting error while sending email "The specified string is not in the form required for an e-mail address." plz help me

Below is the code

string strConnection= System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;

       // string strSelect = "SELECT Username,password FROM registration WHERE emailid = @emailid";
        string strSelect = "SELECT name FROM registration WHERE email_id = @email_id";
 
         SqlConnection connection = new SqlConnection(strConnection);
        SqlCommand command = new SqlCommand();
        command.Connection = connection;
        command.CommandType = CommandType.Text;
        command.CommandText = strSelect;

        //SqlParameter email = new SqlParameter("@emailid", SqlDbType.NVarChar,100);
        SqlParameter email = new SqlParameter("@email_id", SqlDbType.VarChar, 100);
        email.Value = txtEmail.Text.Trim().ToString();
        command.Parameters.Add(email);
      
        DataSet dsPwd = new DataSet();
        SqlDataAdapter dAdapter = new SqlDataAdapter(command);
        connection.Open();
        dAdapter.Fill(dsPwd);
        connection.Close();
        if(dsPwd.Tables[0].Rows.Count > 0 )
        {
            MailMessage loginInfo = new MailMessage();
            //loginInfo.To.Add(txtEmail.Text.ToString());
            loginInfo.To.Add(new MailAddress(txtEmail.Text));
            loginInfo.From = new MailAddress("mail@gmail.com");
            loginInfo.Subject = "Forgot Password Information";
 
            loginInfo.Body = "Username: " + dsPwd.Tables[0].Rows[0]["Username"] + "<br><br>Password: " + dsPwd.Tables[0].Rows[0]["password"] + "<br><br>";
            loginInfo.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "password");
            smtp.Send(loginInfo);
            lblmsg.Text ="Password is sent to you email id,you can now Login";
        }
        else
        {
            lblmsg.Text = "Email Address Not Registered";
        }
    }

推荐答案

我们无法帮助您正确地输入用户!

如果他们输入的内容不是有效的电子邮件地址 [ ^ ]然后它将被拒绝。



尝试:

1)修剪它 - 当你将数据保存到数据库中时这样做,为什么不使用修剪版本作为实际地址?

2)验证它。查看上面的链接并检查数据。如果它无效,则不要将其保存在您的数据库中,只需向用户报告问题!
We can't help you make your users type correctly!
If what they type is not a valid email address[^] then it will be rejected.

Things to try:
1) Trim it - you do that when you save the data into your DB, so why not use the trimmed version as the actual address?
2) Validate it. Look at the link above and check the data. If it is invalid, then don't save it in your DB, just report the problem to the user!


这篇关于我在发送电子邮件时收到错误“指定的字符串不是电子邮件地址所需的格式。”请帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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