Envío de correo desde VB

Antes se enviaba correo desde mi programa de VB utilizando:
Set objSession = CreateObject("mapi.session")
Actualmente ya se desinstalo Outlook y se instalo Outlook Express, esto ya no me funciona.
¿Cómo puedo enviar correos ahora?
¿Existe alguna forma de hacerlo con Outlook express?
¿Puedo enviar de pronto directamente con el servidor de correo?

4 respuestas

Respuesta
1
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5
ShellExecute hwnd, "open", "mailto:[email protected]", vbNullString, vbNullString, SW_SHOW
'------------------------------------
Otra forma
' 1) Open a new project in Visual Basic.
' 2) On the Tools menu, choose References and select the Microsoft CDO 1.21 Library.
' 3) Add a CommandButton to the default form. Accept the default name, Command1.
' 4) Copy the following code into the General Declarations section of the default form:
Option Explicit
Private Sub Command1_Click()
Dim objSession As Object
Dim objMessage As Object
Dim objRecipient As Object
'Create the Session Object
Set objSession = CreateObject("mapi.session")
'Logon using the session object
'Specify a valid profile name if you want to
'Avoid the logon dialog box
objSession.Logon profileName:="MS Exchange Settings"
'Add a new message object to the OutBox
Set objMessage = objSession.Outbox.Messages.Add
'Set the properties of the message object
objMessage.subject = "This is a test."
objMessage.Text = "This is the message text."
'Add a recipient object to the objMessage.Recipients collection
Set objRecipient = objMessage.Recipients.Add
'Set the properties of the recipient object
objRecipient.Name = "John Doe" '<---Replace this with a valid
'display name or e-mail alias
objRecipient.Type = mapiTo
objRecipient.Resolve
'Send the message
objMessage.Send showDialog:=False
MsgBox "Message sent successfully!"
'Logoff using the session object
objSession.Logoff
End Sub
'-------------------------------------------
Very Simple Mail Program using SMTP. Requires you download and reference Dimac's free J Mail component from http://www.dimac.se
Dim Jmail As SMTPMail
Private Sub Form_Load()
' Put 5 TextBoxes for From,To,Subject,Attachment,Message
' Put a commondialog control and a command button adjacent to the
' Attachment Text Box
' and change its caption as Attach...
' Put another Button and change its caption to Send
' Finally copy the code given below to ur form
' Reply to [email protected]
End Sub
Private Sub Command1_Click()
On Error Resume Next
Set Jmail = New SMTPMail
' Change it to ur ServerAddress from where u will send the mails
' Better give the IP address and also give the :25 since the port for smtp is 25
Jmail.ServerAddress = "192.168.10.1:25"
' Change it to ur name as u like here
Jmail.Sender = "Bhaskar"
Jmail.ReplyTo = Text1
Jmail.AddRecipientEx Text2, "<>"
Jmail.Subject = Text4
Jmail.Priority = 1
Jmail.Body = Text3
If Text5 <> "" Then
Jmail.AddAttachment Text5
End If
Jmail.Execute
If Err <> 0 Then
MsgBox Error$, vbCritical, "Mail Error"
Else
MsgBox "Your Mail has been sent to " & Text2
Unload Me
End If
Set Jmail = Nothing
End Sub
Private Sub Command2_Click()
CommonDialog1.ShowOpen
Text5 = CommonDialog1.FileName
End Sub
Espero que esto te ayude un poco
Saludos
Roberto Alvaardo
Cartagena - Colombia
Respuesta
1
Lo que puedes hacer es utilizar los objetos de Outlook, o, si no puedes directamente conectarte al servidor de mail mediante winsock y enviar los comandos.
Utilizando winsock es un poco más rebuscado (si quieres te puedo enviar un ejemplo a tu mail)
Te adjunto el código para enviar un mail de forma rápida
Dim Miaplicacion As Outlook.Application, MiMensaje As Outlook.MailItem
Dim Receptor As Recipient
Dim i As Long
'Abrimos el Outlook y creamos un mensaje nuevo
Set Miaplicacion = CreateObject("outlook.application")
Set MiMensaje = Miaplicacion.CreateItem(olMailItem)
'Añadimos el destinatario
Set Receptor = MiMensaje.Recipients.Add("[email protected]")
Receptor.Type = olTo
MiMensaje.Body = .....
MiMensaje.Subject = .....
MiMensaje.Send
Set MiMensaje = Nothing
Set Miaplicacion = Nothing
End Sub
Esta un poco resumido pero creo que con esto puedes empezar
Respuesta
1
Yo tengo una aplicación que esta funcionando en Outlook Express ahora mientras que antes lo hacia en Outlook, cambiaron y no ha dado problemas.
Directamente al servidor de correo no he conseguido mandar, siempre a través de una cuenta creada desde el Outlook.
Te cuento:
He incluido los componentes Microsoft MAPI Controls
En el formulario añades un MAPISession y un MAPIMessage, en el MAPIMessage, en propiedades, le tienes que poner el usuario y la contraseña de la cuenta de correo que tengas asignada, y luego el código es el siguiente:
'abrir una nueva sesión
MAPIsesion. SignOn
'igualar el id de la sesión al del mensaje
MAPImensaje.SessionID = MAPIsesion.SessionID
MAPImensaje.MsgIndex = -1
'DIRECCIÓN
MAPImensaje.RecipAddress = "Dirección de destino"
'ASUNTO
MAPImensaje.MsgNoteText = "Texto del mensaje"
'FICHERO ANEXADO
MAPImensaje.AttachmentPathName = "Ruta Fichero anexado" (Si quieres)
'envío del mensaje
MAPImensaje. Send
'desconexión
MAPIsesion. SignOff
Con esto debería funcionar, otra cosa a tener en cuenta es que te hayan mantenido la cuenta de correo que tenias anteriormente.
Respuesta
-1
Lamento no poder ayudarte en este momento, te aseguro que en otra oportunidad lo haré con mucho gusto
Hasta pronto.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas