an issue when sending an email through smtp after publishing

Ahmed Alsofi 1 Reputation point
2022-09-01T20:42:24.83+00:00

****I have created a webpage using asp.net with vb that has some fields after filling the fields click on submit then an email sends. it's working fine on my local host but after publishing it to the hosting company I get this error :**

Server Error in '/' Application.
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 173.194.76.109:587

/api/attachments/236986-untitled.jpg?platform=QnA

I used this code:-

    Dim mail As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()  
                Dim strBody As String = ""  
               mail.To.Add("******@gmail.com")  
            mail.From = New MailAddress("******@gmail.com")  
                  mail.Subject = "New Booking"  
                strBody = "<b>Name:</b>" & " " & FirstName.Text & " " & Middlename.Text & " " & Surname.Text & "<br><br>"  
                strBody += "<b>Phone Number: </b>" & phone.Text & "<br><br>"  
                strBody += "<b>Email: </b>" & txtEmail.Text & "<br><br>"  
                strBody += "<b>Booking From: </b>" & " " & Bfrom.Text & "  <b>at:</b>" & time1.Value & "<br><br>"  
                strBody += "<b>Booking to: </b>" & " " & Bto.Text & "  <b>at:</b>" & Time2.Value  
                mail.Body = strBody  
               mail.IsBodyHtml = True  
                mail.Priority = Net.Mail.MailPriority.Normal  
            Dim smtp As SmtpClient = New SmtpClient()  
            smtp.Host = "smtp.gmail.com"  
                 smtp.Port = 587  
            smtp.UseDefaultCredentials = True  
            smtp.Credentials = New System.Net.NetworkCredential("******@gmail.com", "password")  
            smtp.EnableSsl = True  
            smtp.Send(mail)  
           smtp.DeliveryMethod = SmtpDeliveryMethod.Network  
            lbltxt.Attributes("style") = "color:green;"  
                Bto.Focus()  
                lbltxt.Text = "Your Booking has been Successfully Sent"  
Developer technologies | ASP.NET | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 30,191 Reputation points Microsoft External Staff
    2022-09-05T07:55:42.52+00:00

    Hi @Ahmed Alsofi ,
    You can try these methods:
    1.Check if it is a firewall issue. Create inbound and outbound rules in the firewall settings to open ports.
    2.Try to use the local IP of the server hosting the website.
    3. Try to configure proxy settings in the Web.config file.

    <system.net>   
        <defaultProxy>   
                <proxy usesystemdefault = "false" proxyaddress="http://address:port" bypassonlocal="false"/>   
        </defaultProxy>   
    </system.net>  
    

    https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/defaultproxy-element-network-settings
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.