J
John
Hi
How does one send email from within a vb.net app?
Thanks
Regards
How does one send email from within a vb.net app?
Thanks
Regards
Hi
How does one send email from within a vb.net app?
Hi
How does one send email from within a vb.net app?
Thanks
Regards
Here's a simple way
Public Sub StartMail(ByVal [To] As String, Optional ByVal subj As String
= "", Optional ByVal Body As String = "")
Try
Dim mailProcess As New ProcessStartInfo
mailProcess.UseShellExecute = True
mailProcess.FileName = "mailto:" & [To] & "?subject=" & subj
& "&body=" & Body
Process.Start(mailProcess)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Here's my favorite way but it's 2005 only
Dim msg As New System.Net.Mail.MailMessage
Dim smtp As New System.Net.Mail.SmtpClient
msg.From = New System.Net.Mail.MailAddress("(e-mail address removed)")
msg.To.Add("(e-mail address removed)")
msg.Subject = "Test Msg"
msg.Body = "Can you hear me now?"
smtp.Host = "smtp.myco.com"
smtp.Port = 25
smtp.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
smtp.Credentials = New
System.Net.NetworkCredential("(e-mail address removed)", "mypass")
smtp.Send(msg)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Got one more I'll find later.
Hi
How does one send email from within a vb.net app?
Thanks
Regards
cj said:Dim myMAPISession As New MSMAPI.MAPISession
Dim myMAPIMessage As New MSMAPI.MAPIMessages
cj said:I use Thunderbird and most folks use Outlook here and it works fine for
us as I have it in the example. Fine being the way I want it too that
is. Seems I do recall something that was different in the way Outlook
and Thunderbird responded to it but can't remember what.
cj said:Here's the other. I haven't used it in 2005 yet but in 2003 I did. I
used it to give a user of an app the option to send the contents of say a
text box to someone. It brings up their default mail and puts the
contents and subject in but leaves who they're sending it to blank and
allows them to edit the message etc and send it themselves.
My 2005 example in the previous email is used by some of my programs to
wake us up in the middle of the night with an email to our cell phones
because something happened it didn't like. In other words it is a
totally automatic generate and send of a message.
I don't quite remember how the sendto: works any more--it didn't do what I
wanted.
There are other ways to do this but these are all the examples I have.
Private Sub SndMAPIMail(ByVal subj As String, ByVal msg As String)
Try
Dim myMAPISession As New MSMAPI.MAPISession
Dim myMAPIMessage As New MSMAPI.MAPIMessages
myMAPISession.DownLoadMail = False
myMAPISession.SignOn()
myMAPISession.NewSession = True
myMAPIMessage.SessionID = myMAPISession.SessionID
myMAPIMessage.Compose()
myMAPIMessage.MsgSubject = subj
myMAPIMessage.MsgNoteText = msg
Try
myMAPIMessage.Send(True)
Catch ex As Exception
If Not ex.Message = "User cancelled process" Then
MessageBox.Show(ex.Message)
End If
End Try
myMAPISession.SignOff()
myMAPISession.NewSession = False
Catch
End Try
End Sub
Here's a simple way
Public Sub StartMail(ByVal [To] As String, Optional ByVal subj As String
= "", Optional ByVal Body As String = "")
Try
Dim mailProcess As New ProcessStartInfo
mailProcess.UseShellExecute = True
mailProcess.FileName = "mailto:" & [To] & "?subject=" & subj
& "&body=" & Body
Process.Start(mailProcess)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Here's my favorite way but it's 2005 only
Dim msg As New System.Net.Mail.MailMessage
Dim smtp As New System.Net.Mail.SmtpClient
msg.From = New System.Net.Mail.MailAddress("(e-mail address removed)")
msg.To.Add("(e-mail address removed)")
msg.Subject = "Test Msg"
msg.Body = "Can you hear me now?"
smtp.Host = "smtp.myco.com"
smtp.Port = 25
smtp.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
smtp.Credentials = New
System.Net.NetworkCredential("(e-mail address removed)", "mypass")
smtp.Send(msg)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Got one more I'll find later.
Hi
How does one send email from within a vb.net app?
Thanks
Regards
Spam Catcher said:MAPI is Messaging API... if you have an antivirus it often blocks MAPI
commands. MAPI can only relied on in an enterprise environment in which
you
have complete control of the computers.
Many thanks cj for wonderful examples. How do attachments work?
Many Thanks
Regards
cj said:Here's the other. I haven't used it in 2005 yet but in 2003 I did. I
used it to give a user of an app the option to send the contents of say a
text box to someone. It brings up their default mail and puts the
contents and subject in but leaves who they're sending it to blank and
allows them to edit the message etc and send it themselves.
My 2005 example in the previous email is used by some of my programs to
wake us up in the middle of the night with an email to our cell phones
because something happened it didn't like. In other words it is a
totally automatic generate and send of a message.
I don't quite remember how the sendto: works any more--it didn't do what I
wanted.
There are other ways to do this but these are all the examples I have.
Private Sub SndMAPIMail(ByVal subj As String, ByVal msg As String)
Try
Dim myMAPISession As New MSMAPI.MAPISession
Dim myMAPIMessage As New MSMAPI.MAPIMessages
myMAPISession.DownLoadMail = False
myMAPISession.SignOn()
myMAPISession.NewSession = True
myMAPIMessage.SessionID = myMAPISession.SessionID
myMAPIMessage.Compose()
myMAPIMessage.MsgSubject = subj
myMAPIMessage.MsgNoteText = msg
Try
myMAPIMessage.Send(True)
Catch ex As Exception
If Not ex.Message = "User cancelled process" Then
MessageBox.Show(ex.Message)
End If
End Try
myMAPISession.SignOff()
myMAPISession.NewSession = False
Catch
End Try
End Sub
Here's a simple way
Public Sub StartMail(ByVal [To] As String, Optional ByVal subj As String
= "", Optional ByVal Body As String = "")
Try
Dim mailProcess As New ProcessStartInfo
mailProcess.UseShellExecute = True
mailProcess.FileName = "mailto:" & [To] & "?subject=" & subj
& "&body=" & Body
Process.Start(mailProcess)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Here's my favorite way but it's 2005 only
Dim msg As New System.Net.Mail.MailMessage
Dim smtp As New System.Net.Mail.SmtpClient
msg.From = New System.Net.Mail.MailAddress("(e-mail address removed)")
msg.To.Add("(e-mail address removed)")
msg.Subject = "Test Msg"
msg.Body = "Can you hear me now?"
smtp.Host = "smtp.myco.com"
smtp.Port = 25
smtp.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
smtp.Credentials = New
System.Net.NetworkCredential("(e-mail address removed)", "mypass")
smtp.Send(msg)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Got one more I'll find later.
John wrote:
Hi
How does one send email from within a vb.net app?
Thanks
Regards
Antivirus, at least the McAfee on my server, will also block messages
that aren't in MAPI.