

Imports System.Net.Mail
Imports System.Text
'Imports MailKit.Net.Smtp
'Imports MailKit.Security
'Imports Microsoft.Exchange.WebServices.Data
'Imports MimeKit


Public Class frmSendEmail



    'Public Shared Sub Simple()

    '    Dim mensagem = New MimeMessage()
    '    mensagem.From.Add(New MailboxAddress("melqui", "melqui.serrano@gmail.com"))
    '    mensagem.[To].Add(New MailboxAddress("suporte tecnico", "suporte.tecsol@arimuya.com"))
    '    mensagem.Subject = "teste email"
    '    Dim builder = New BodyBuilder()
    '    builder.TextBody = "holatestando"
    '    builder.Attachments.Add("C:\Users\arimuya\Documents\BNM.csv")
    '    mensagem.Body = builder.ToMessageBody()
    '    Try
    '        Dim client = New SmtpClient()
    '        client.ConnectAsync("smtp.gmail.com", 587, SecureSocketOptions.Auto)
    '        client.AuthenticateAsync(_settings.Value.Email, _settings.Value.Password)
    '        client.SendAsync(EmailMessage)
    '        client.DisconnectAsync(True)
    '    Catch ex As Exception
    '        Dim e = ex
    '        Throw
    '    End Try

    'End Sub


    'Private Sub enviar_emamil()

    '    Dim smtp As New System.Net.Mail.SmtpClient
    '    Dim correo As New System.Net.Mail.MailMessage
    '    '  Dim adjunto As System.Net.Mail.Attachment

    '    With smtp


    '        .Credentials = New System.Net.NetworkCredential("melqui.serrano@gmail.com", "Serran035-")
    '        .UseDefaultCredentials = True
    '        .EnableSsl = True
    '        .Port = 587
    '        .Host = "smtp.gmail.com"
    '        ' .Timeout = 100 * 60 * 10

    '        .DeliveryMethod = SmtpDeliveryMethod.Network

    '    End With

    '    'adjunto = New System.Net.Mail.Attachment("fichero adjunto al correo")

    '    With correo

    '        .From = New System.Net.Mail.MailAddress("melqui.serrano@gmail.com")
    '        .To.Add("suporte.tecsol@arimuya.com")
    '        .Subject = "estamos testando"

    '        .Body = "<strong>estamos haciendo un nuevo teste de este projeto</strong>"

    '        .IsBodyHtml = True
    '        .Priority = System.Net.Mail.MailPriority.High
    '        '  .Attachments.Add(adjunto)

    '    End With

    '    Try
    '        smtp.Send(correo)
    '        '  correo.Disconnect(True)
    '        MessageBox.Show("El mensaje de correo ha sido enviado con éxito.", "Correo enviado", MessageBoxButtons.OK)
    '    Catch ex As Exception
    '        MessageBox.Show("Error: " & ex.Message, "Error al enviar el correo", MessageBoxButtons.OK)
    '    End Try





    'End Sub

    'Public Sub SendMessage()
    '    Dim msg As String = ""

    '    Select Case CurrEmailType
    '        Case EmailType.PRENOTA
    '            msg = PrenotaSubject
    '            FromMailAddress = PrenotaFromAddress
    '        Case EmailType.INFO
    '            msg = InfoSubject
    '            FromMailAddress = InfoFromAddress
    '    End Select

    '    Dim subject As String = String.Format(msg, message.Nome, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"))
    '    Dim body As String = String.Format("Nome : {0}" & vbLf & "Numero : {1}" & vbLf & "E-Mail : {2}" & vbLf & "Messaggio :" & vbLf & "{3}", message.Nome, message.Telefono, message.Email, message.Messaggio)
    '    Dim message = New MimeMessage()
    '    message.From.Add(FromMailAddress)
    '    message.[To].Add(ToAddress)
    '    message.Subject = subject
    '    message.Body = New TextPart("plain") With {
    '    .Text = body
    '}

    '    Try

    '        Using client = New SmtpClient()
    '            client.Connect("smtp.gmail.com", 465, True)
    '            client.AuthenticationMechanisms.Remove("XOAUTH")
    '            client.Authenticate("carrozzeria@splendorsrl.it", "At066bn1!")
    '            client.Send(message)
    '            client.Disconnect(True)
    '        End Using

    '        Result = EmailResult.SUCCESS
    '        MessageResult = "Messaggio inviato correttamente"
    '    Catch ex As Exception
    '        Result = EmailResult.FAIL
    '        MessageResult = ex.Message
    '    End Try
    'End Sub



    Public Sub EnviaMail()


        Dim client As SmtpClient = New SmtpClient()
        client.Host = "smtp.gmail.com"
        client.Port = 587
        client.EnableSsl = True
        client.Credentials = New System.Net.NetworkCredential("melqui.serrano@gmail.com", "Serran035-")

        Dim mail As MailMessage = New MailMessage()
        mail.Sender = New System.Net.Mail.MailAddress("melqui.serrano@gmail.com", "Melqui")
        mail.From = New MailAddress("melqui.serrano@gmail.com", "Melqui")
        mail.To.Add(New MailAddress("suporte.tecsol@arimuya.com", "suporte tecnico"))
        mail.Subject = "Lembrete de senha"
        mail.SubjectEncoding = Encoding.GetEncoding("ISO-8859-1")
        mail.Body = "Olá ! estamos tetando dados "
        mail.BodyEncoding = Encoding.GetEncoding("ISO-8859-1")
        mail.IsBodyHtml = True
        mail.Priority = MailPriority.High

        Try
            client.SendMailAsync(mail)
            MsgBox("Email enviado com sucesso!")
        Catch erro As System.Exception
            MsgBox("Erro ao enviar e-mail: ")
        Finally
            mail = Nothing
        End Try


    End Sub




    Private Sub btnEnviar_Click(sender As Object, e As EventArgs) Handles btnEnviar.Click
        ' Call enviar_emamil()
        Call EnviaMail()
    End Sub
End Class


