473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Sending email from within app

Hi

How does one send email from within a vb.net app?

Thanks

Regards
Apr 27 '07 #1
14 4629
"John" <Jo**@nospam.infovis.co.ukwrote in news:OnwQ$ZNiHHA.4228
@TK2MSFTNGP03.phx.gbl:
Hi

How does one send email from within a vb.net app?

..NET 1.1 System.Web.Mail

..NET 2.0 System.Net.Mail
Apr 27 '07 #2
cj
There are several ways. Also depends on if your using 2003 or 2005.
I'll pull some of my code and get back to you.
John wrote:
Hi

How does one send email from within a vb.net app?

Thanks

Regards

Apr 27 '07 #3
cj
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@myco.com")
msg.To.Add("bo*@ACME.com")
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@myco.com", "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

Apr 27 '07 #4
On Apr 27, 10:15 am, "John" <J...@nospam.infovis.co.ukwrote:
Hi

How does one send email from within a vb.net app?

Thanks

Regards
You should find your answers here:

www.systemnetmail.com
www.systemwebmail.com

Thanks,

Seth Rowe

Apr 27 '07 #5
cj
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@myco.com")
msg.To.Add("bo*@ACME.com")
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@myco.com", "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
Apr 27 '07 #6
cj <cj@nospam.nospamwrote in news:#N**************@TK2MSFTNGP06.phx.gbl:
Dim myMAPISession As New MSMAPI.MAPISession
Dim myMAPIMessage As New MSMAPI.MAPIMessages
I would avoid using MAPI unless the user has MS Outlook.

Apr 27 '07 #7
cj
????

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.
Spam Catcher wrote:
cj <cj@nospam.nospamwrote in news:#N**************@TK2MSFTNGP06.phx.gbl:
> Dim myMAPISession As New MSMAPI.MAPISession
Dim myMAPIMessage As New MSMAPI.MAPIMessages

I would avoid using MAPI unless the user has MS Outlook.
Apr 27 '07 #8
cj <cj@nospam.nospamwrote in news:OH**************@TK2MSFTNGP05.phx.gbl:
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.
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.
Apr 27 '07 #9

See (and download code)
/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)
http://sholliday.spaces.live.com/blog/

The code is in C#, but you can learn the principals.

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:On**************@TK2MSFTNGP03.phx.gbl...
Hi

How does one send email from within a vb.net app?

Thanks

Regards


Apr 27 '07 #10
Many thanks cj for wonderful examples. How do attachments work?

Many Thanks

Regards

"cj" <cj@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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@myco.com")
msg.To.Add("bo*@ACME.com")
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@myco.com", "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

Apr 27 '07 #11

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
cj <cj@nospam.nospamwrote in news:OH**************@TK2MSFTNGP05.phx.gbl:
>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.

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.

Antivirus, at least the McAfee on my server, will also block messages that
aren't in MAPI.

I just went through that yesterday. McAfee was set to permit sending by the
popular email programs, and I had to add two extra exceptions for the .net
application - one when running the app directly in the development
environment, and another when running over the web. After poking around in
McAfee, I found a log stating what it was blocking, and then I added it to
the list of exceptions under McAfee's setting dealing with the block of
"mass email worms on port 25"

Jeff
--
Posted via a free Usenet account from http://www.teranews.com

Apr 28 '07 #12
cj
I haven't done much with them. But, I know it can be done. If I was
you I'd cut and paste my examples into a test prg and when they work try
adding attachments in a similar manner to recipients or the subject and
body text. I have a program that I use for testing little bits of code
and ideas. It's a form with 36 buttons currently and a couple of
textboxes and labels. Each button was added to test a bit of code.
When I wrote the apps that send email I made a button in the test
program and played with the code there until I got the button to send a
message. That is where the code I sent you came from. It'll be Monday
before I can look into attachments--and that's if I'm not swamped with
problems when I get in the office. Good Luck.

John wrote:
Many thanks cj for wonderful examples. How do attachments work?

Many Thanks

Regards

"cj" <cj@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>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@myco.com")
msg.To.Add("bo*@ACME.com")
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@myco.com", "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

Apr 28 '07 #13
Many thanks cj for wonderful examples. How do attachments work?

For the System.Net.Mail class:

http://www.systemnetmail.com/faq/3.4.1.aspx

For the System.Web.Mail class:

http://www.systemwebmail.com/faq/2.3.aspx

Thanks,

Seth Rowe

Apr 28 '07 #14
"Jeff" <no**@nothingX.comwrote in
news:46**********************@free.teranews.com:
Antivirus, at least the McAfee on my server, will also block messages
that aren't in MAPI.
Isn't it better to run the "mailto:xx*@xxx.com" command instead? That way
the OS will automatically launch the default mail program without the need
to worry about the AV?
Apr 28 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: BaWork | last post by:
I have a web form where a client can select which site members to send an email to. This form is populated from the contents of the member table, so the form can have 0-x names listed on it...
1
by: Devonish | last post by:
I am composing an email with Access VB and then sending it from within Access. Everything works correctly (the email actually goes!) but Outlook ask some irritating questions that the user is...
8
by: Frank | last post by:
I think I've confused myself completely here :-) I have used System.Web.Mail, but am not sure if this works with Exchange Server 5.5. I asked the client if they're email server supported SMTP, and...
6
by: Anuradha | last post by:
Dear All How can i send mails using vb.net Thanx all
0
by: Jim Devenish | last post by:
I wish to send a copy of an email to a selected number of recipients. I can do this when the email contains only text but have a problem when the email contains a picture. I create a new email...
3
by: JaffaCakes | last post by:
I want to send an email confirmation after a user completes a form on our Internet page. I am testing this with the System.Web.Mail.SmtpMail class. If I do a SmtpMail.Send then the message takes...
1
by: gemma.gill | last post by:
Hi There, I have a button on a form within access that sends a verification e- mail. My problem is that these e-mails are sending from individual user accounts rather than a genieric mailbox. ...
2
by: Smithers | last post by:
I have a service that will periodically send email messages to system adminstrators. I would like for this service to send a email notification whenever the service is started and when it is...
1
by: Mel via AccessMonster.com | last post by:
I have four people on my email list. I want to send one email each of the four people with a list of accounts over due, embodied within the email. So, for instance, jeff will be sent an email...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.