Link to home
Start Free TrialLog in
Avatar of persheng
persheng

asked on

How to send email through a VB application ?

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
ASKER CERTIFIED SOLUTION
Avatar of SNilsson
SNilsson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of krinpit
krinpit

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
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
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
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
 
Yes Venkat, I agree :)
Avatar of persheng

ASKER

everybody thankyou very much.My problem has been solved.
P.S: Dear Venkat thanks for your explanation.
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
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.
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
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

try to use Mapi32.dll
U can use WinSock tool to achieve solution. But u have to customize o your own..
You could use the object in CDO.

Scott Wiseman
<advertizing removed per http:help.jsp#hi106>
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
I did something similiar to this using this script

www.avidware.net
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.
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)

You could download a SMTP dos Facility. And make a VB script to Write a Batch file and run it.
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
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
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
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?
Hi dbdoshi,

Try using a well known ISP's SMTPserver

For example: I use mail1.eircom.net
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



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. !!
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
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.
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