Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Vb to send email

Status
Not open for further replies.

nhidalgo

MIS
Jun 13, 2001
619
US
Can someone give me a link or some instruction on how to use vb6.0 to send email.
Thanks for any help

Nick
 
You can use winsock, but I'm afraid I'm no expert on it (in fact, I'm just in the early phases of starting my first program using it).

Do a search for it here, in a search engine or try There is loads of stuff on it.
 
Winsock1.SendData &quot;From: <&quot; + txtSender.Text + &quot;>&quot; + vbCrLf + _
&quot;To: &quot; + txtReceiver.Text + vbCrLf + _
&quot;Subject: &quot; + txtSubject.Text + vbCrLf + _
&quot;X-Mailer: Invoicemail v1.0&quot; + vbCrLf + _
&quot;Mime-Version: 1.0&quot; + vbCrLf + _
&quot;Content-Type: text/&quot; + Check1.Tag + vbTab + &quot;charset=us-ascii&quot; + vbCrLf + vbCrLf + _
txtMessage.Text
Winsock1.SendData vbCrLf + &quot;.&quot; + vbCrLf

I have this code in my application. Is it possible to add a line to include an attachment as a variable.

Thanks for all the help
Nick
 
Have you tried using Outlook?

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

Set objOutlook = CreateObject(&quot;Outlook.Application&quot;)
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(&quot;emailaddress&quot;)

objOutlookRecip.Type = olTo

.Subject = subject
.Body = body
.Importance = olImportanceHigh
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing


Just another option,

drost
 
I tried the code in the FAQ using the outlook object. This seems to work fine except that outlook pops up with a dialog saying &quot;A program is trying to send an email on your behalf. It could be a virus. Do you want to allow this. &quot; to which a user has to answer yes before sending it. I was planning on using this to email me whenever an error is trapped in an application i'm working on so i will know what the error is before a client even calls about it. Obviously a dialog popping up about viruses sending mail is not a good thing. Wondering if anyone knows a way to turn this off?

TIA

P.S. The outlook version is 10 (Office XP) Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
I've written a VB program that uses outlook to send out emails to groups of support folks. The compiled program is complete and available for download for free off my web site at: It's called Mail-It! However I do not have the code enabled for an attachment. I'd be happy to send you the code complete, however right now I am not on my home PC where that code resides. If you would like complete code email me and let me know after you check out the compiled program on my web site. I'd be happy to email the complete code to you or post here in this forum for any/all to use as well.
 
I am able to send messages with vb, just not sure how to add an attachment. in the code. yes go ahead and email me the code, or possible just the code for the attachment.
nhidalgo@mail.com

THanks
Nick
 
There have been a few posts on how to do it with Winsock, but IMHO they weren't too clear. Here's full Winsock code to send an email (totally transparent to user except for blinky modem lights :))

Code:
Dim inString As String

Sub SendMail(mailServer as string, mailTo as String, mailFrom as String, mailSubject as String, mailBody as String)

Dim Dummy As String

Winsock1.Close
Winsock1.Connect mailServer, 25  'SMTP port
Do
 DoEvents
Loop Until Winsock1.State = 7  'may wanna add timeout code here

Dummy = GetData()  'wait for standard hello message
Winsock1.SendData &quot;HELO &quot; & Winsock1.LocalIP & vbLf

Dummy = GetData()  'send the RSET code (to send the message correctly)
Winsock1.SendData &quot;RSET&quot; & vbLf

Dummy = GetData()
Winsock1.SendData &quot;MAIL FROM:&quot; & mailFrom & vbLf

Dummy = GetData()
Winsock1.SendData &quot;RCPT TO:<&quot; & mailTo & &quot;>&quot; & vbLf

Dummy = GetData()
Winsock1.SendData &quot;DATA&quot; & vbLf

Dummy = GetData()
Winsock1.SendData &quot;Subject: &quot; & mailSubject & vbLf
Winsock1.SendData Replace(mailBody, vbCrlf, vbLf) & vbLf & &quot;.&quot; & vbCrLf

Dummy = GetData()
Winsock1.SendData &quot;QUIT&quot;

Dummy = GetData  'connection is now closed

End Sub

Function GetData() As String

inString = &quot;&quot;

Do
 DoEvents
Loop Until inString > &quot;&quot;

GetData = inString

End Function

Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

Winsock1.GetData inString

End Sub

Yeesh, that's a lot of typing, and it's not too clear. But it is the code to send an email through Winsock. And, it's not the best code...it doesn't do any error checking on anything. You may want to add that.

Hope this helps...(it better help some, that still was a lot of typing)
~Bryan B
 
For those of you in a commercial environment be warned that this is a beta product (but does look like an interestingly different approach to that of Redemption)
 
Update to my Feb 20, 2002 post ... the code is no longer at the URL provided for download. If interested in acquiring just drop me an email.

BTW - have been using the non-beta version of the software in my November, 2004 post ( ) and it works wonderfully ... and it is still available for free.

Jim Null
[afro]
 
I usually use one of the CDO Libraries. There are numerous postings on this forum regarding sending e-mail. Search for sending email using CDO.

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top