Re: Sending email from within app



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


cj wrote:
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("me@xxxxxxxx")
msg.To.Add("bob@xxxxxxxx")
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("me@xxxxxxxx", "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

.



Relevant Pages

  • Re: Opening Excel from Access
    ... Dim MDBName As String, DefaultDirectory As String, SQLStg As String ... If MsgBox("Do you want to use this database in future?", ... Dim Msg As String ...
    (comp.databases.ms-access)
  • Re: Sending email from within app
    ... Private Sub SndMAPIMail(ByVal subj As String, ByVal msg As String) ... Dim myMAPIMessage As New MSMAPI.MAPIMessages ... How does one send email from within a vb.net app? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Attachments problems with Redemption
    ... Dim o ... Public Sub sendEmail(MsgTo As String, MsgSubject As String, msg As ... Dim msgBase As String ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: How to programmatically refresh linked tables
    ... MyPath As String) As Boolean ... Dim MyDB As DAO.Database ... Dim tdf As DAO.TableDef ... Dim Msg As String ...
    (comp.databases.ms-access)
  • Re: How to programmatically refresh linked tables
    ... MyPath As String) As Boolean ... Dim MyDB As DAO.Database ... Dim tdf As DAO.TableDef ... Dim Msg As String ...
    (comp.databases.ms-access)