我可以在 localHost 上发送 smtp 消息,但我不能在 Live WebSite 上发送它

I can send smtp message on a localHost But i cant send it on a Live WebSite

我使用 Asp.net 我的项目中有 Umbraco CMS 我使用剃刀语法

实现了发送消息

我正在提交一个 from 到以下剃须刀语法

@{ if (IsPost)
{
    string name = Request["name"];
    string email = Request["email"];
    string phone = Request["phone"];
    string city = Request["city"];
    string note = Request["note"];
    NetworkCredential basicCredential =new NetworkCredential("*****@gmail.com", "******");
    MailMessage mail = new MailMessage();
    //var from = new MailAddress(Email.Text);
    mail.From = new MailAddress(email);
    mail.To.Add("tupacmuhammad5@gmail.com");
    mail.Subject = "Torcan WebSite Contact Us";
    mail.IsBodyHtml = false;
    mail.Body = "You just got a contact email:\n" +
                "Name: " + name + "\n"
                + "Email: " + email + "\n"
                 + "TelePhone: " + phone + "\n"
                + "Address: " + city + "\n"
                  + "Message: " + note + "\n";
    SmtpClient smtp = new SmtpClient();
    smtp.Port = 587;
    smtp.UseDefaultCredentials = false;
    smtp.Host = "smtp.gmail.com";

    smtp.Credentials = basicCredential;
    smtp.EnableSsl = true;
    try
    {
        smtp.Send(mail);
    }
    catch (Exception ex)
    {


    }
    finally
    {
        smtp.Dispose();
    }


}

}

它在我的 localHost 上运行完美但在实时服务器上它会引发运行时错误 "after i remove the try catch "

我找不到问题所在 我在 umbraco 后台模板中编写此代码 我在其他国家/地区拥有服务器,但我无法访问它有任何帮助吗?请 ?

问题是服务器位于德国,所以当服务器试图打开我的 Gmail 帐户时。这是一个不同的国家,从未见过那里的行动。 所以我所要做的就是通过浏览器在服务器机器上通过远程访问打开我的gmail并确认是我然后一切正常。