Hi All,
I am developing an application wherein I need to send one data report through the application to a specific e-mail address. How can I do it?
Printable View
Hi All,
I am developing an application wherein I need to send one data report through the application to a specific e-mail address. How can I do it?
The simplest code to send emails is this: (you need to have Outlook installed)
[Cimperiali: colored and indented for better readingCode:Dim objOutlook As Object
Dim objOutlookMsg As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0)
With objOutlookMsg
.To = "[email protected]
.Cc = "[email protected]"
.Subject = "Hello World (one more time)..."
.Body = "This is the body of message"
.HTMLBody = "HTML version of message"
.Attachments.Add ("c:\myFileToSend.txt")
.Send 'Let´s go!
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
I have the same question. I tried this code and it works great. Thanx.
But how do I get the location of the data report in order to attach it? I wasn't saving them, just creating them for printing purposes.
But phinds
when I tried the code I got an error like "ActiveX cannot create object..." at line 3 :(
Suhaib
Suhaib,
That code automates the Microsoft Outlook Express, and it is required that you have the software installed in the machine.
The best thing is to use winsock with SMTP protocol with a bit of MIME. Check the threads it was posted somewhere I just couldn't remember. Try searching the RFC's for SMTP as well as MIME, it's worth reading.
Check this thread:
http://www.codeguru.com/forum/showth...hreadid=232562
I think the really simplest way is to use VB's MAPI controls and BTW the code automates Outlook, too.
My copy of VB6 contained a Sample of sending email through VB. Perhaps yours does too. I just defaulted all directories when installing VB and the location of that sample was placed at:
C:\Program Files\Microsoft Visual Studio\MSDN\99OCT\1033\Samples\VB98\misc\Vbmail
Maybe you can check your PC for same to get some hints.
A note: outlook.application is Outlook, not the express one. But what Thread1 said changes really few, as you must have outlook installed to make that code work..Quote:
Originally posted by Thread1
Suhaib,
That code automates the Microsoft Outlook Express, and it is required that you have the software installed in the machine.
Thanks to Cimperiali for the correction..:cool:
I'm not quite sure on this. But you just only need the Outlook *.olb file? to get this running?Quote:
Originally posted by Cimperiali
A note: outlook.application is Outlook, not the express one. But what Thread1 said changes really few, as you must have outlook installed to make that code work..
Look at attached txt
'*********
'* Reloaded
'*********
This is somethingh I found surfing the web
I think you're right, but this are non-redistributable files, so technically, you have to have Outlook installed.Quote:
But you just only need the Outlook *.olb file? to get this running?
Cimperiali: Wow, you're really going out of your way for us!! thank you very much for doing research for us and compiling the email code. Maybe those should be in the FAQ??
I know this might not be related, but I hope some one can help me. I'm using "phinds" code, with Outlook 2000 installed. Now when ever I try to send an e-mail, outlook gives me a message saying that a program is trying to send an email on your behafe bla bla and I have to click yes or no, I know this is a security function, but can it be disabled??? so that outlook will send the e-mail without giving that message?!
Thanks and Regards,
Boiling Ice
This is a security patch that was introduced a while back with Win 2000 SP2 or Outlook 2000 SP2 or something like that. Couldn't find a way to get around it for now unless not using Outlook to send email.
This explains how to get around the outlook security popup if you have admin rights to the exchange server.
http://www.microsoft.com/office/ork/...ndx/appa11.htm
Hope this helps.
LJ
Hi,Quote:
Originally posted by lsmeteor
This is a security patch that was introduced a while back with Win 2000 SP2 or Outlook 2000 SP2 or something like that. Couldn't find a way to get around it for now unless not using Outlook to send email.
Infact, the code given to send an e-mail from a VB program really works great.
Wonderful!!!!!!!!!!
But, I want to know if there is an alternate way of doing it, I mean without the Outlook in picture.
Thanks & Regards,
Lavanya
You can use the winsock and talk to the email server via SMTP. A sample code has already provided in the previous posts, take a look at Cimperiali's 5 ways to send email thru VB.
Quote:
Originally Posted by phinds
This works OK- but it sends mail the before the user can enter text into the body. I'd like to bring up Outlook, start an empty Email , fill in the TO: address, subject, and maybe a line of two in the Body, then allow the user to fill in the rest of the body of the message, then send it, after they finish typing it.
I've looked in the FAQ and the Five Ways to send email- they are variations on yoru method. I can't get the command line completion to work on the objOutlook object, so I cant see the other methods.
i managed to send out an email successfullyQuote:
Originally Posted by Cimperiali
but would like to find out is it possible to do formatting for the body of the email which sends out by outlook? meaning something lk
We received your response.
Please note that your reference number is <number>.
Please furthur correspond with us using this reference number.
Thank You.
Company Name.
the reference number part is not a prob, but the line breaks are the headache ..
Hi,
Why dont u Use a String Variable and set it to like that :
lBody = "We received your response." & chr(13) & "Please note that your reference number is " & Num & chr(13) & "Please furthur correspond with us using this reference number." & chr(13) & chr(13) & "Thank You."
and then pass it to the Body part
.Subject = "Hello World (one more time)..."
.Body = lBody
I hope it should Work for you !
I think that the easiest method whould be something likeQuote:
Originally Posted by Toracle
Hope this helps....Code:Public MSG_Str as string
MSG_Str = "We received your response." & chr(10) & chr(13) & "Please note that your reference number is" .........
With objOutlookMsg
.To = "[email protected]
.Cc = "[email protected]"
.Subject = "Hello World (one more time)..."
.Body = MSG_Str
.Attachments.Add ("c:\myFileToSend.txt")
.Send 'Let´s go!
End With
Gremmy
it works! thanks!Quote:
Originally Posted by GremlinSA
one last question. if i were to add a company name at the end like say "Toracle Pte Ltd" and would like it to be bold. How do i make it bold?
Hi,Quote:
Originally Posted by Cimperiali
I have tried 3rd way (using winsock control)
but getting run time error with no 424.
Can you plz suggest
if you want formatting for your email, i think you have to use the winsock version and try to implement the MIME. Using "text/html" mime you can tke advantage of the HTML formatting.Quote:
Originally Posted by Toracle
at what part of the code?Quote:
Originally Posted by omshivaprasad
Have a look atQuote:
Originally Posted by lsmeteor
http://www.contextmagic.com/express-clickyes/
This solved the problem for me.
Error is in the line SendEmail ....
in command1 button.
I have created two buttons,
one control of winsock
all the code is copied..
Private Sub Command1_Click()
SendEmail txtEmailServer.Text, txtFromName.Text, txtFromEmailAddress.Text, txtToEmailAddress.Text, txtToEmailAddress.Text, txtEmailSubject.Text, txtEmailBodyOfMessage.Text
Please suggest modifications
hi
i used that code and it does open outlook. but the problem is that it does not send the mail. it says verify e-mail address in the account settings.
pls help me.
thanx in advance
Ajay.N.Moorthy
It is very simple!!!!!!!!!!!!!!!!!!!
Imports System.Net.Mail
Imports System.Net.AuthenticationSchemes
Imports System.Net
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Send.Click
SendTo = TextBox2.Text
Message = TextBox3.Text
subject = TextBox1.Text
Dim myclient2 As New SmtpClient("p99-smtp.mail.me.com")
Dim nc2 As New NetworkCredential((email here, password")
myclient2.Credentials = nc2.GetCredential("p99-smtp.mail.me.com", 993, "Auto")
Dim mailme As New MailMessage(email, SendTo, subject, Message)
myclient2.SendAsync(mailme, mailme)
End Sub
HOPE IT HELPS!!!!!!!!!!!!!!!
The question is 8 years old! I doubt the poster is still searching for a solution.
Aside from that the answer just posted is not using the correct language so it would not help even if the poster was still looking.
AND there are no code tags! :)
Hi,Quote:
This works OK- but it sends mail the before the user can enter text into the body. I'd like to bring up Outlook, start an empty Email , fill in the TO: address, subject, and maybe a line of two in the Body, then allow the user to fill in the rest of the body of the message, then send it, after they finish typing it.
I've looked in the FAQ and the Five Ways to send email- they are variations on yoru method. I can't get the command line completion to work on the objOutlook object, so I cant see the other methods.
why don't you use vbsendmail.dll .you can send mail without outlook !.Just download the vbsendMail.dll from following web site .and place VbsendMail.dll into system32 folder .
http://www.freevbcode.com/ShowCode.asp?ID=109.
step 2.
just copy vbsendmail.dll it into sytem32 folder .
step 3
register this using regsvr32
step 4
write the following declaration in the general section of your form .where you want to use this code .
Code:Private WithEvents poSendMail As vbSendMail.clsSendMail
Private Function SendMail()
Set poSendMail = New vbSendMail.clsSendMail
poSendMail.SMTPHost = "SMTP.GMAIL.COM" 'here smtp server
poSendMail.From = "[email protected]" 'From where y want to send .
poSendMail.FromDisplayName = "FEEROZE"
poSendMail.RecipientDisplayName = "xx;mm" 'Put receipients Name
poSendMail.Recipient = ""[email protected]"[/COLOR]][email protected] " 'Type your Receipient name .to whom y want to send
poSendMail.CcDisplayName = "Wof;Datamiser;David" 'Write Carbon copy as per your convenience
poSendMail.CcRecipient = " " ' in this property you can write Recipient Email
poSendMail.Subject = "Email Demo" 'You can type subject in subject property of PosendMail object.
poSendMail.message = "please find your attachment "
poSendMail.Attachment = "C:\Log\" & Attachment FileName
poSendMail.Send
Set poSendMail = Nothing
End Function:wave::wave:
Once again someone posting to an 8 year old thread, would be nice if people would take the time to look at other posts and perhaps even the date of the post before pulling a long dead thread back to the top of the list.
No longer recommended, as too many people had problems. (Or OUTLOOK was changed after Office 2000) Should actually TRY the code, before you post it for others to follow
AND:
Should be the last straw...Quote:
.SMTPHost = "SMTP.GMAIL.COM" 'here smtp server
poSendMail.From = "[email protected]" 'From where y want to send .
poSendMail.FromDisplayName = "FEEROZE"
poSendMail.RecipientDisplayName = "xx;mm" 'Put receipients Name
poSendMail.Recipient = ""[email protected]"[/color]][email protected] " 'Type your Receipient name .to whom y want to send
poSendMail.CcDisplayName = "Wof;Datamiser;David" 'Write Carbon copy as per your convenience
poSendMail.
Here is a Simple way to do this, No Outlook required, No win-socket Required.
Just add this Library to your project and use this function for send emails from VB applications.
Microsoft CDO for Windows 2000 Library
Code:
Public Sub SendEMail(lTo As String, LSubject As String, lAttchCount As Integer, lBody As String, Optional SingalFile As String, Optional lAttchements)
On Error GoTo erh
Dim Correio As CDO.Message
Set Correio = CreateObject("CDO.Message")
Correio.From = """ABC Org"" <[email protected]>"
Correio.To = lTo
Correio.BCC = "[email protected], [email protected]"
Correio.Subject = LSubject
Correio.TextBody = lBody
If lAttchCount = 1 Then
Correio.AddAttachment SingalFile
End If
Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"
Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "abc123"
Correio.Configuration.Fields.Update
Correio.Send
Exit Sub
erh:
MsgBox Err.Description, vbApplicationModal + vbInformation, "My App"
Exit Sub
End Sub
hello i used below code but still error 530 5.7.0 must issue a STARTTLS command first.
iam trying to send mail to gmail anybody tell me what i put wrong above codeCode:Dim UserName$, UserMail$, MailRecipiant$, MailBody$, SockData$
Private Sub Command1_Click()
UserName = "[email protected]"
UserMail = "leonscott136<[email protected]>"
MailRecipiant = UserMail
MailBody = "The message goes here"
Winsock1.LocalPort = 0
Winsock1.RemoteHost = "smtp.gmail.com"
Winsock1.RemotePort = 587
Winsock1.Connect
End Sub
Private Sub Winsock1_Connect()
Label1 = "Sending message..."
Winsock1.SendData "EHLO " & UserName & vbCrLf
If Not WaitFor("250") Then GoTo 100
Winsock1.SendData "MAIL FROM: " & UserMail & vbCrLf
If Not WaitFor("250") Then GoTo 100
Winsock1.SendData "RCPT TO: " & MailRecipiant & vbCrLf
If Not WaitFor("250") Then GoTo 100
Winsock1.SendData "DATA" & vbCrLf
If Not WaitFor("354") Then GoTo 100
Winsock1.SendData MailBody & vbCrLf & "." & vbCrLf
If Not WaitFor("250") Then GoTo 100
Winsock1.SendData "QUIT" & vbCrLf
If Not WaitFor("221") Then GoTo 100
Label1 = "Message sent"
GoTo 200
100
Label1 = SockData
200
Winsock1.Close
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData SockData
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Label1 = "Error: " & Description
SockData = "Error"
Winsock1.Close
End Sub
Private Function WaitFor(SockResponse As String) As Boolean
Do While Left(SockData, 3) <> SockResponse And Left(SockData, 3) <> "220" And Left(SockData, 3) <> "250"
DoEvents
If Left(SockData, 3) > "400" Then Exit Function
Loop
WaitFor = 1
SockData = ""
End Function
You should describe in more detail what happens or what happens NOT.
Have you verified that a connection to smtp.gmail.com has been established?
Also, IIRC this error message does not necessarily mean your SMTP implementation is faulty. (I didn't closely examine your code though, one of the reasons being that it's pretty hard to read without the code tags.) It may just mean that the server you're connecting to requires you to use TLS but your SMTP implementation doesn't support that.
I have no experience with smtp.gmail.com, so I don't know whether that should work without TLS. I suggest you run a test with a server of which you know for sure that it doesn't require TLS. I'm afraid though that, in case that actually is the problem, implementing the entire TLS protocol yourself in VB6 would be a lot of work...
HTH
This thread is too old to keep repeating the same thing...
@leonscott136:
That Winsock code looks a lot like what I've posted in the past. I believe it fails because gmail requires a secure connection (causing the TLS related error). This document details what needs to be done: https://tools.ietf.org/html/rfc3207
Whether you'd be able to fulfill the requirements using only Winsock is another matter. It may work with some servers and not others. I've not pursued it, but I suspect it'd require more work than it's probably worth.