Tuman Sahu

Tuman Sahu

  • 1.8k
  • 61
  • 543

SMS & Email does not work in IIS but running in Local Server

Dec 11 2019 12:44 AM
I am making a project for safety. Here i want to sent SMS and Email to end user  my SMS and Email function code is bellow. This code is running is Local Server very smoothly and don't know why its not fuctioning in IIS .
Can any one help me what is the actual problem ? 
 
 
Dim ForSendMessage As String = " ID : " & uc.ID.ToString() & " Is Assign For Unsafe Act/Condition :" & Session("UnsafeMsg").ToString()
Dim strUrl As String = "Using One SMS API Code"
Dim request As WebRequest = HttpWebRequest.Create(strUrl)
Dim response As HttpWebResponse = DirectCast(request.GetResponse, HttpWebResponse)
Dim s As Stream = DirectCast(response.GetResponseStream(), Stream)
Dim readStream As New StreamReader(s)
Dim dataString As String = readStream.ReadToEnd()
lblAssigntoMobile.Text = dataString.ToString
response.Close()
s.Close()
readStream.Close()
Dim st As String = lblAssigntoMobile.Text
Dim subst As String = st.Substring(17, 4)
If subst <> "3001" Then
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "alert", "alert('" & subst.ToString & "')", True)
Else
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "alert", "alert('Message Sent')", True)
End If
Dim mail As MailMessage = New MailMessage()
Const username As String = "myemailid"
Const password As String = "myemailpassword"
Dim smtpclient As SmtpClient = New SmtpClient()
Dim fromaddress As MailAddress = New MailAddress("myemailid")
smtpclient.Host = "smtp.gmail.com"
smtpclient.Port = 587
mail.From = fromaddress
mail.[To].Add(lblAssigntoEmailId.Text)
mail.Subject = ("Hi Test Mail")
mail.IsBodyHtml = True
mail.Body = "<html><head><title>" & HttpUtility.HtmlEncode("Safety Mail") & "</title></head><body style='height:600px'>" & "<p>" + HttpUtility.HtmlEncode(Session("UnsafeMsg").ToString()) & "</p>" & "</body></html>"
smtpclient.EnableSsl = True
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network
smtpclient.Credentials = New System.Net.NetworkCredential(username, password)
smtpclient.Send(mail)
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "alert", "alert('Mail has been sent!!,ID:" & uc.ID & "')", True)
 

Answers (4)