Solved

How to send email through a VB application ?

Posted on 2003-11-11
30
136,216 Views
Last Modified: 2012-05-04
Hi everybody,

I want to send an email to multi users through my VB application.
I don't know if I can use a VB class for this case or I should download a smtp mail component.
I would be thankful if you can suggest me the best solution.
Please give me a code example for former solution or introduce me an effective free, permanent component.

Thank you in advance
Persheng
0
Comment
Question by:persheng
30 Comments
 
LVL 8

Accepted Solution

by:
SNilsson earned 250 total points
Comment Utility
0
 

Expert Comment

by:krinpit
Comment Utility
0
 
LVL 1

Expert Comment

by:vkaushik
Comment Utility
You can download the smtp.ocx which is freely available on the net. Its damn easy to use it to send mails.

SITE IS http://www.vb4all.net/

you can get the smtp.ocx from the site below:
http://www.vb4all.net/products.asp?id=41

or a free download from the site
http://www.filebot.org/Development/ActiveX/item2244-2.htm


Also there is sample code on this site which uses MAPI TO SEND EMAIL.
http://www.vb4all.net/source.asp?id=0&id2=42

I myself have used this smtp.ocx in an industry application and it works fine.

Cheers,
Kaushik
0
 
LVL 1

Expert Comment

by:vkaushik
Comment Utility
Wait,
        I think now everything is shareware. I have a free copy somewhere. Will find out and if you can give me ur mail id will send it to you by tomorrow.

Cheers,
Kaushik
0
 

Expert Comment

by:vinaikk
Comment Utility
others might have suggest . see you can use the mail in 2 ways 1. use any email client (eg MS Outlook)
2. use MAPI controls
what i would suggest is you configure you mail box in the local pc where the program will run and use Outlook object  in your program.  
The code ..
--------------------
Dim mOutLookApp As Outlook.Application
Dim mNameSpace As Outlook.NameSpace
Dim mItem As Outlook.MailItem

Set mOutLookApp = New Outlook.Application
Set mNameSpace = mOutLookApp.GetNamespace("MAPI")
mNameSpace.Logon ,, False, True

    Set mItem = mOutLookApp.CreateItem(olMailItem)
    mItem.To = strEmailAddress
    mItem.Subject = "This is for you"
    mItem.HTMLBody = strMessage
   
    mItem.Sensitivity = olConfidential
    mItem.Importance = olImportanceHigh
   
    mItem.Send
---------------------
yu can change the parameters asper your wish for mNameSpace.Logon as this is the one whihc logs you on to the messaging network
0
 

Expert Comment

by:N_K_venkat
Comment Utility
Hi,
  I Used VBsendMail.dll component and it is working fine.U can get the source code for the dll and for sending Mail(VB) at
http://www.freevbcode.com/ShowCode.Asp?ID=109( See the code/vbSendMail.zip at the bottom of the Page).

Just give the SMTP Id for outgoing u can send mails.U can find a document which contains all properties,Methods etc which will help u.

if u have any doubts u can contact me at venkisubramanian@hotmail.com
Regards,
Venkat
 
0
 
LVL 8

Expert Comment

by:SNilsson
Comment Utility
Yes Venkat, I agree :)
0
 

Author Comment

by:persheng
Comment Utility
everybody thankyou very much.My problem has been solved.
P.S: Dear Venkat thanks for your explanation.
0
 
LVL 1

Expert Comment

by:tfmiltz
Comment Utility
I am very surprised that no one posted a solution that incorporates an MX Lookup - thus removing any necessity on any intermediary SMTP server.

Hands down, even over some commercial solutions - GSMAIL  (free by the war) is the ONLY component that does this MX Lookup AND will push out an email over SMTP.

What does this mean ?  

This means you can send email from your VB app WITHOUT having to specify an SMTP server.

Without doubt you have entertained automated error reporting via email from VB, only to hit the barrier of finding or requesting permission to use clients SMTP server.

Now ?  No more:   As a prototype -  I've included a simple sub called ReportError

I occasionally for one reason or another will have my apps fire off emails, regardless if my client has configured or even HAS an SMTP server.

Code as follows -  to use ?  simply download the GSMAIL componed from here:
http://www.visualbuilder.com/component/viewcomponent.asp?id=360&devid=1

Public Sub ReportError()
 Dim Res As Variant 'The result of a method call.
    Dim SMTP As New GSMAILLib.SMTP
    Dim sDNS, sMX, sSQL As String
    Dim s1, s2, s3, s4 As String

    Dim sContent As String
    On Error GoTo 0
   
    Set SMTP = New GSMAILLib.SMTP
   
    sDNS = GetDNSinfo
    sDNS = Trim(sDNS)
    sMX = Trim("YOUR_RECIPIENT_EMAIL_ADDRESS_HERE")
    sMX = Mid(sMX, InStr(1, sMX, "@") + 1)

    'Open the SMTP session.
   
   
   
    Res = SMTP.Open(sMX)
    sContent = "Error #" & lErrorNumber & " in Procedure" & sProcedure & "." & vbCrLf
    sContent = sContent & "Description: " & sErrorDescription & vbCrLf
  '  sContent = sContent & "User Comments:" & Text1.Text & vbCrLf
    sContent = sContent & "Build: " & App.Major & "." & App.Minor
   
    'Send the email.
    s1 = "bugreport_centran2000@cdatasource.com"
    s2 = "bugreport_centran2000@cdatasource.com"
    s3 = "Error #" & lErrorNumber
    s4 = sContent
   
    Res = SMTP.Send(s1, s2, s3, s4)
bSkipError = False
End Sub





Again, note, no specification of SMTP server :)  


Tim Miltz
Chief Technology Officer
Etaion Software
0
 

Expert Comment

by:titan203
Comment Utility
hi , in this case you must let your PC to be a server than install an freeware call WmailTo. it got the feature
 SMTP (email) sender
 NNTP (news) poster
 Multiple receivers of emails, grouped as "to", "cc" and "bcc". "Bcc" (blind carbon copy) receivers will not be listed in the message header and is therefore conveniant for mass-mailing of newsletters and information.
 Support for crossposting to several newsgroups when used as a news poster.
 Feature to insert one or several text files to the message body.
 Feature to include one or several binary/text files as binary attachments (using MIME 1.0 multipart/base64 encoding). The encoded message format is the current "standard" and can be read by all modern mail readers.
 Feature to turn off MIME encoding to handle old mail systems or special tasks.
 Feature to convert DOS codepage (european) character sets to the Windows OEM charset. This allows you to use national caharcters in a DOS window, and have these converted to the Windows chracter set by the program. This feature is very conveniant if you need to send the output from some DOS program throug email.
 Easy to configure SMTP host and personal information - have some fun with your buddies by sending them a letter from the president or something similar (note - this actually is illegal, so you should only do this with people you know well, and _be there_ when they get the mail).
 Full source code in c++ is included
 so u can download it.

or you can go to http://www.planet-source-code.com to find your solution.
0
 

Expert Comment

by:zuboss82
Comment Utility
Dear All

No Need to use a third party component for sending a mail.Need to install IIS and the mail can be send by simple code in VB
0
 

Expert Comment

by:vinaikk
Comment Utility
else you can use the MAPI control in this manner

MAPISession1.NewSession = False
MAPISession1.LogonUI = True

MAPISession1.SignOn

MAPIMessages1.SessionID = MAPISession1.SessionID
'MAPISession1.Action

MAPIMessages1.Compose
MAPIMessages1.RecipAddress = "vinai.karunakaran@icici-infotech.com"

'MAPISession1.MsgReceiptRequested = True
MAPIMessages1.MsgSubject = "MIS Schedular mails"    

MAPIMessages1.MsgNoteText = "test"
MAPIMessages1.Send

MAPISession1.SignOff

0
 
LVL 1

Expert Comment

by:alankwan
Comment Utility
try to use Mapi32.dll
0
 
LVL 3

Expert Comment

by:harsha_dp
Comment Utility
U can use WinSock tool to achieve solution. But u have to customize o your own..
0
 

Expert Comment

by:Scott659
Comment Utility
You could use the object in CDO.

Scott Wiseman
<advertizing removed per http:help.jsp#hi106>
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Expert Comment

by:hardik_nt
Comment Utility
hi,
u have to options:-
1)use MAPI
 in this first case u need a valid user account in outlook ,it isi simple.like following code:-
Private Sub Command1_Click()
MAPISession1.DownLoadMail = False
MAPISession1.UserName = "user"
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.MsgSubject = Text4.Text
MAPIMessages1.MsgNoteText = RichTextBox1.Text
MAPIMessages1.RecipAddress = Text1.Text
MAPIMessages1.Send
MAPISession1.SignOff
End Sub

2)use winsock control.
  in this case u have to handle all the things from sockets to sevrer etc.
 so i recommend use mapi.u can code a simple program according to ur needs.

kind reagards
-hardik shah
www.hardikshah.cjb.net
0
 

Expert Comment

by:Scott659
Comment Utility
I did something similiar to this using this script

www.avidware.net
0
 

Expert Comment

by:pgins
Comment Utility
I use
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

Success = ShellExecute(0&, vbNullString, "mailto:xxx@xxxxx.xxx?subject=yyyyy", vbNullString, "C:\", 1)

And works fine,
Paul.
0
 
LVL 4

Expert Comment

by:thedude112286
Comment Utility
This is the fully .NET way to do it.

Imports System.Web.Mail

Dim mailMessage as MailMessage = new MailMessage
mailMessage.From = "You@server.com"
mailMessage.To = "YourMail@yourserver.com
mailMessage.Subject = "Hello World"
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
mailMessage.Attachments.Add(New MailAttachment(pathToAttach))
mailMessage.Body = "Hello World"
            
SmtpMail.SmtpServer = "smtpServer" // your smtp server's address
SmtpMail.Send(mailMessage)

0
 
LVL 1

Expert Comment

by:shanekelly_7
Comment Utility
You could download a SMTP dos Facility. And make a VB script to Write a Batch file and run it.
0
 

Expert Comment

by:manishkaushik
Comment Utility
Hi  thedude112286

I am using the same with adding the reference of system.web dll
but i m facing 1 error can u please guide me !

An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll

Additional information: Could not access 'CDO.Message' object.


Thanks
0
 

Expert Comment

by:aregan
Comment Utility
Hi Tim Miltz,

That component you refer to 'GSMail' is no longer available at the URL you suggested.
Would you have a copy I could try or suggest somewhere to get it from ?

Regards,

Alan
0
 
LVL 4

Expert Comment

by:thedude112286
Comment Utility
Sorry for the delay, I just got back from vacation.  This faq is dedicated entirely to your problem.
http://www.systemwebmail.com/faq/4.2.3.aspx
0
 

Expert Comment

by:dbdoshi
Comment Utility
Hi, I am trying to send email through a .net app without using local SMTP server. I also looked at a java program to do the same thing. But both programs seems to need a host and port to connect. How do I get the SMTP server of the recepient?
0
 

Expert Comment

by:krinpit
Comment Utility
Hi dbdoshi,

Try using a well known ISP's SMTPserver

For example: I use mail1.eircom.net
0
 
LVL 1

Expert Comment

by:tfmiltz
Comment Utility
DbDoshi,

    You are asking how to find the recipients Mail Exchange Server, for this you need to do an MX Lookup.   JUST as you would do an A Record lookup to see what the web server is for a given domain, e.g.  (abc.com),  you perform an MX lookup against the DNS server to see what the SMTP server associated with such a domain is registered to, so,  to find the web IP for abc.com, you do an A record lookup, to find the email server associated with abc.com, you do an MX Lookup.

   Just stip off the domain from the email address, and either via sockets, or some high level component, as I recommended above (the ONLY one I know of that does both the MX lookup FOR YOU, AND the direct send via sockets) GMail from Goldenseal studios, free of charge for non commercial use.  To be found here->

http://www.goldsealstudios.com/downloads.html

   Many mail servers though will do a check back against the senders address/IP to see if it HAS an MX Lookup associated with it, or some means to try to validate it's not coming from some spam spewer, as you can imagine, direct send is REALLY what is happening with any mail server - at the end of the day so to speak.  What's happening is, you are establishing a connection, following SMTP protocol, over TCP/IP - you shake hands with the server, let it know you've got something, ask if they exist, and drop it off, all through very special reserved words set in stone 20 + years ago, when the standard was invoked.

  The component above has been extremely useful for me in automated emailings from applications I've built and NOT wanted to rely on the user having a default mail server configured, as, I myself don't and only use web based email, no thanks to MS VBS in outlook, and other dangers.  

   If you are looking to quietly send data from a clients instance of your application you've distributed though (of course, you need to specify what you're doing in the EULA or - well - get sued),  I recommend XMLHTTP coupled with ASP/ASP.net on some dedicated server just living to catch requests/posts for this, or some similar server based processing model for incoming requests/posts.   I have found that clients firewalls don't even trigger using this approach, and again, I can't stress enough, make SURE you have that in the EULA, myself ? I'm nice, I bring up a box if for error reporting stating,  Send, Do Not Send, as Microsoft does, if used for error reporting.

   Hope this more than answered your question, not sure if this is still open, I don't need any more points, heh, I'm just happy to help you understand the basics here of MX Lookup - the Mail Exchange record associated with a domain that is set for the last stop DNS server responsible for such a domain, AND the ability to do a lookup, by stripping domain off of email address, AND the simplicity and beuty of GMail from GoldenSeal, which, technically, is a real nice mail server by definition, free, lightweight, AND via COM, abstracts ALL of the SMTP jargon you'd otherwise have to master, JUST to send an email through code WITHOUT having to specify an SMTP server on the clients machine to send from.

Tim Miltz
Senior... Senior... Senio... something or another...
Etaion Software



0
 

Expert Comment

by:dbdoshi
Comment Utility
Tim, thank you very much in taking time to reply. I figured out how to do it myself after searching quite a bit. The problem was there was not one reference (atleast that I could find) which explained what you explained. So had to hunt quite a bit to get my program going. I wish there was an explanation like yours about a month ago. !!
0
 

Expert Comment

by:ferasdeeb
Comment Utility
I can help u writing the solution using C# and u can translate it to VB..

add new linkLabel to ur form ... go to its Tag property and write the following:

mailto: blabla@blabla.com
 double click on the linkLabel then write:
System.Diagnostics.Process.start(linkLabel.Tag.ToString());

thats it .. good luck
0
 

Expert Comment

by:cmacapili
Comment Utility
hi! i've tried the shell command to send email.. is there anyway that i can send emails without opening it, i mean i want my program to just automatically send the mail, one that i dont have to click "send" to be be able to send it. Coz what my program does is open a mail browser, i still have to click the send button to be able to send it. I prefer shell command if possible. thanks.
0
 

Expert Comment

by:HopperSI
Comment Utility
I use the following VB script to in my login script to send an email. It points to the SMTP server. No third party software is needed.

Does anyone know how to insert the computername, time and/or date in the message body?
Set objEmail = CreateObject("CDO.Message")
 

objEmail.From = "From@domain.com"

objEmail.To = "To@domain.com"

objEmail.Subject = "Subject Text" 

objEmail.Textbody = "Text body." 

objEmail.Configuration.Fields.Item _

    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objEmail.Configuration.Fields.Item _

    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _

        "SMTP server name" 

objEmail.Configuration.Fields.Item _

    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objEmail.Configuration.Fields.Update

objEmail.Send

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual xHarbour 1 74
dividesSelf challange 15 77
array6 challenfge 6 62
tidtcpserver connection lost handle 2 41
This article will show, step by step, how to integrate R code into a R Sweave document
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now