Visual Basic.NET - Envio de correos Outlook

 
Vista:

Envio de correos Outlook

Publicado por gerardo (2 intervenciones) el 07/03/2014 10:05:13
Hola. Por si alguien me puede ayudar.

Envio correos por Outlook de la forma:

1
2
3
4
5
6
7
8
Dim oApp As Outlook._Application
oApp = New Outlook.Application()
Dim oMsg As Outlook._MailItem
oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
oMsg.Subject = asunto
oMsg.HTMLBody = cuerpo
oMsg.To = corele.Text
oMsg.Send()

necesito enviar el mensaje con un usuario de correo que no es el predeterminado. En definitiva necesito algo que sustituya a:

1
oMsg.from= "envio@micorreo.com"

no encuentro esta propiedad para dicho objeto

Gracias. Un saludo
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 29
Ha aumentado su posición en 2 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Envio de correos Outlook

Publicado por apacheco (98 intervenciones) el 20/03/2014 13:16:36
Yo utilizo esta rutina para enviar e_mails. No depende de Outlook, y te permite cambiar el correo de emisor, aunque yo lo en este caso lo utilizo fijo; y ES OBLIGATORIO DARLE LA CLAVE DEL USUARIO DE ENVIO.

Le paso 2 destinos, ya que no permite como direccion de correo destino1; destino2, y lo que hece es añadirlos a una coleccion. Lo mismo pasa con las Copia (CC si es visible y Bcc si es oculta)

Imports System.Net.Mail

Public Sub Enviar_Mail(ByVal origen As String, _
ByVal destino1 As String, _
ByVal destino2 As String, _
ByVal copia1 As String, _
ByVal copia2 As String, _
ByVal asunto As String, _
ByVal texto As String, _
Optional ByVal adjunto1 As String = Nothing, _
Optional ByVal adjunto2 As String = Nothing, _
Optional ByVal adjunto3 As String = Nothing, _
Optional ByVal adjunto4 As String = Nothing, _
Optional ByVal adjunto5 As String = Nothing)

Dim Mensaje As New System.Net.Mail.MailMessage()
Dim Servidor As New System.Net.Mail.SmtpClient
Dim Archivo As String
Servidor.Credentials = New System.Net.NetworkCredential("[email protected]
", "password")
Servidor.Host = "pepito.es" ' Servidor
'Servidor.Port = 25
'Servidor.EnableSsl = True ' Si necesita SSL

Mensaje.From = New System.Net.Mail.MailAddress("[email protected]
", "password"), System.Text.Encoding.UTF8)
Mensaje.[To].Add(destino1)

If destino2 <> String.Empty Then
Mensaje.[To].Add(destino2)
End If

If copia1 <> String.Empty Then
Mensaje.Bcc.Add(copia1)
End If

If copia2 <> String.Empty Then
Mensaje.Bcc.Add(copia2)
End If

Mensaje.Subject = asunto
Mensaje.Body = texto

If Not IsNothing(adjunto1) And _
adjunto1 <> String.Empty Then
Archivo = adjunto1
Dim Attach1 As New System.Net.Mail.Attachment(adjunto1, System.Net.Mime.MediaTypeNames.Application.Octet)
Mensaje.Attachments.Add(Attach1)
End If

If Not IsNothing(adjunto2) And _
adjunto2 <> String.Empty Then
Archivo = adjunto2
Dim Attach2 As New System.Net.Mail.Attachment(Archivo, System.Net.Mime.MediaTypeNames.Application.Octet)
Mensaje.Attachments.Add(Attach2)
End If

If Not IsNothing(adjunto3) And _
adjunto3 <> String.Empty Then
Archivo = adjunto3
Dim Attach3 As New System.Net.Mail.Attachment(Archivo, System.Net.Mime.MediaTypeNames.Application.Octet)
Mensaje.Attachments.Add(Attach3)
End If

If Not IsNothing(adjunto4) And _
adjunto4 <> String.Empty Then
Archivo = adjunto4
Dim Attach4 As New System.Net.Mail.Attachment(Archivo, System.Net.Mime.MediaTypeNames.Application.Octet)
Mensaje.Attachments.Add(Attach4)
End If

If Not IsNothing(adjunto5) And _
adjunto5 <> String.Empty Then
Archivo = adjunto5
Dim Attach5 As New System.Net.Mail.Attachment(Archivo, System.Net.Mime.MediaTypeNames.Application.Octet)
Mensaje.Attachments.Add(Attach5)
End If

Try

Servidor.Send(Mensaje)

Catch ex As Exception
'MostrarError("Modulo E_Mail", "Envio_1", Err.Number, _
' "ERROR AL ENVIAR EL E_MAIL", _
' vbCritical + vbOKOnly, _
' "MODULO DE ENVÍO DE E_MAIL'S")

Throw New Exception("ERROR AL ENVIAR EL E_MAIL")

Finally
Mensaje = Nothing
Servidor = Nothing

End Try

End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar