Jump to content

enviar mail vb.net


manuelbarreto
 Share

Recommended Posts

Olá amigos eu tou a fazer um formulario para enviar mails tenho este seguinte codigo:     

Mas n me está a dar erros mas tb nao envia o mail alguem me pode dar uma ajuda?? obg

 Dim correo As New System.Net.Mail.MailMessage

        correo.From = New System.Net.Mail.MailAddress("mail do utilizador")
        correo.To.Add("manuel.domingues.barreto@gmail.com")
        correo.Subject = "com"
        correo.Body = "ola"
        correo.IsBodyHtml = True

        correo.Priority = System.Net.Mail.MailPriority.Normal

        Dim smtp As New System.Net.Mail.SmtpClient
        smtp.Host = "smtp.gmail.com"
        smtp.Credentials = New System.Net.NetworkCredential("mail", "password")
        smtp.EnableSsl = True


        Try
            smtp.Send(correo)

        Catch ex As Exception

        End Try
Link to comment
Share on other sites

Acrescenta Msgbox(ex.Message) no catch, para ter a certeza de que não está a ser lançada nenhuma excepção.

Como usa SSL, exprimenta trocar a porta do padrão para a 995, 465 ou 587 ou até mesmo sem SSL.

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Link to comment
Share on other sites

ve se assim já consegues, basicamente tens de meter a porta como o Ribeiro55 disse =)

Imports System.Net.Mail
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New _Net.NetworkCredential("utelizador@gmail.com", "password")
            SmtpServer.Port = 587
            SmtpServer.Host = "smtp.gmail.com"
            mail = New MailMessage()
            mail.From = New MailAddress("o_teu_utilizador@gmail.com")
            mail.To.Add("email_da_pessoa_em_questao@xxx.xxx")
            mail.Subject = "Teste"
            mail.Body = "Mensagem de teste"
            SmtpServer.Send(mail)
            MsgBox("Enviado com sucesso")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.