No e-mail enough

Asked

Viewed 55 times

0

I am trying to assemble a code for sending email on my page. No error occurs, but I also do not receive the email. Would anyone know why?

Default.aspx.Vb

Protected Sub btnEnviar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnEnviar.Click
    Dim Mensagem As MailMessage = New MailMessage()
    Dim Email As New SmtpClient()
    Dim basicAuthenticationInfo As New System.Net.NetworkCredential("[email protected]", "password", "smtp.jnmoura.com.br")

    Email.Host = "smtp.jnmoura.com.br"
    Email.Port = 587
    Email.EnableSsl = False
    Email.UseDefaultCredentials = True
    Email.Credentials = basicAuthenticationInfo
    Email.DeliveryMethod = SmtpDeliveryMethod.Network

    Mensagem.From = New MailAddress("[email protected]")
    Mensagem.To.Add(New MailAddress("[email protected]"))
    Mensagem.To.Add("[email protected]") 

    Mensagem.Subject = "Teste de envio de email"
    Mensagem.Body = "TESTE"

    Mensagem.IsBodyHtml = False
    Mensagem.Priority = MailPriority.High

    Email.Send(Mensagem)

End Sub

Web.config

<system.net>
<mailSettings>
  <smtp>
    <network
         host="smtp.jnmoura.com.br"
         port="587"
         userName="[email protected]"
         password="password"
         enableSsl="true"
    />
  </smtp>
</mailSettings>

1 answer

0


I was able to solve the problem with the following code

Default.aspx.Vb

Protected Sub btnEnviar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnEnviar.Click
    Dim Mensagem As MailMessage = New MailMessage()
    Dim Email As New SmtpClient()

    Email.Host = "smtp.jnmoura.com.br"
    Email.Port = 587

    Mensagem.From = New MailAddress("[email protected]")
    Mensagem.To.Add(New MailAddress("[email protected]"))

    Mensagem.Subject = "Teste de envio de email"
    Mensagem.Body = "TESTE"

    Mensagem.IsBodyHtml = False
    Mensagem.Priority = MailPriority.High

    Email.Send(Mensagem)

End Sub

Web.config

<system.net>
<mailSettings>
  <smtp>
    <network
         host="smtp.jnmoura.com.br"
         port="587"
         userName="[email protected]"
         password="password"
         enableSsl="false"
    />
  </smtp>
</mailSettings>

  • Could explain what was wrong and what changed in the guy’s code...

  • 1

    First I cleaned the excess code (unused). I practically changed the enableSsl from true to false in web.config and left a fixed email in Default.aspx.Vb’s Message.From

Browser other questions tagged

You are not signed in. Login or sign up in order to post.