Search code examples
c#asp.net-mvcrazorsmtpumbraco

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


enter image description hereim using Asp.net And I have the Umbraco Cms on my project i implemented The Send message using razor syntax

im submitting a from to the following razor syntax

@{ 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();
    }


}

}

it works perfect on My localHost But on a live server its thorws a runtime error "after i remove the try catch "

i cant find out what seems to be problem im writing this code in umbraco backoffice tamplate i have the server on onther country and i dont have access to it any help ? please ?


Solution

  • The Problem was that the Server is located in Germany so when the server tries to open my Gmail account. its a different country and never seen action from there. so all i had to do is to open my gmail via remote access on the server machine via a browser and confirmed it was me then every thing worked perfectly.