|
-
Feb 25th, 2011, 06:57 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] send email with vb6 with smtp
I have develop an application that need to notify admin when somethings goes wrong through email?
How do i send an email :
1 without popping up outlook to the user?
2 and make sure that the message was sent?
am not sending mass email or what ever, just less that 2kb email message that needs to be sent describing the error that has occurred in the app.
thanks
-
Feb 25th, 2011, 07:39 AM
#2
Re: send email with vb6 with smtp
You can either use CDO or vbsendmail for sending emails.
You can find many samples if you search this forums.
http://www.vbforums.com/search.php?searchid=2910939
Check the CodeBank too: http://www.vbforums.com/forumdisplay.php?f=91
-
Feb 25th, 2011, 09:51 AM
#3
PowerPoster
Re: send email with vb6 with smtp
I am using this code to send emails to customers without any intervention on the part of the operator. It requires that Microsoft Outlook is running, though.
Code:
Dim oApp As Outlook.Application
Dim oEmail As Outlook.MailItem
Set oApp = New Outlook.Application
Screen.MousePointer = vbHourglass
'==============================================
' FEDERAL PACKAGE
'==============================================
fax = Dir("Z:\DAD\FAXES\FAX1.TXT")
If fax <> "" Then
Set oEmail = oApp.CreateItem(olMailItem)
With oEmail
.To = "[email protected]"
.Subject = "Production Report"
.BodyFormat = olFormatPlain
.Body = "Attached is the Production Report"
.Attachments.Add "Z:\DAD\Faxes\Fax1.txt", olByValue
.Recipients.ResolveAll
.Save
.Send
End With
Set oEmail = Nothing
End If
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Feb 25th, 2011, 12:02 PM
#4
Thread Starter
Fanatic Member
Re: send email with vb6 with smtp
dose it require outlook installed or it requires outlook running.
-
Feb 25th, 2011, 12:08 PM
#5
PowerPoster
Re: send email with vb6 with smtp
In my case, yes, you will get an error if Outlook is not installed and running.
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Feb 25th, 2011, 02:40 PM
#6
Thread Starter
Fanatic Member
Re: send email with vb6 with smtp
Ok thanks, but i can use your technique. it will fail if another version of outlook was installed than the one used to test it.
-
Feb 25th, 2011, 03:48 PM
#7
Re: send email with vb6 with smtp
CDO would be a better choice, especially on a server. You're not really supposed to be installing Outlook on servers for automated use, and CDO was provided specifically to handle such things.
My guess: no code handout, solution not accepted. True?
-
Feb 27th, 2011, 02:59 PM
#8
Thread Starter
Fanatic Member
Re: send email with vb6 with smtp
ok thanks, i finnaly settled for CDO. But one question, will it work in win7 and vista ?
-
Feb 28th, 2011, 11:37 AM
#9
Re: send email with vb6 with smtp
Yes, but be careful to set the Configration properly.
There is a lot of bad sample code on the Web that naively relies on CDO initializing based on the current user's Outlook Express or Outlook profile. These often fail on user's computers where Outlook Express does not exist or is not set up for the user. Windows 7 doesn't support OE at all, and Vista had a modified version (Windows Mail) that tends to protect its settings from casual use in this way.
Configuration CoClass
In many cases, the default configuration settings are sufficient to send and post messages successfully. The default configuration settings depend on the software installed on the computer on which you are using the CDO component. When you send messages without associating a Configuration object, these defaults are used; for example, if the computer has the SMTP service installed, the default configuration for sending messages is to write them into files in the SMTP pickup directory. Additionally, various settings can be loaded from Microsoft® Outlook® Express if it is installed. For more information about default settings, see the configuration fields section of the reference.
You might start here if you haven't read the documentation yet.
Last edited by dilettante; Feb 28th, 2011 at 11:43 AM.
-
Feb 28th, 2011, 12:41 PM
#10
Thread Starter
Fanatic Member
Re: send email with vb6 with smtp
see the code i used
vb Code:
Public Function SendMail(sTo As String, sSubject As String, sFrom As String, _
sBody As String, sSmtpServer As String, iSmtpPort As Integer, _
sSmtpUser As String, sSmtpPword As String, bSmtpSSL As Boolean) As String
On Error GoTo SendMail_Error:
Dim lobj_cdomsg As CDO.Message
Set lobj_cdomsg = New CDO.Message
lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = sSmtpServer
lobj_cdomsg.Configuration.Fields(cdoSMTPServerPort) = iSmtpPort
lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL
lobj_cdomsg.Configuration.Fields(cdoSMTPAuthenticate) = 1
lobj_cdomsg.Configuration.Fields(cdoSendUserName) = sSmtpUser
lobj_cdomsg.Configuration.Fields(cdoSendPassword) = sSmtpPword
lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 30
lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = 2
lobj_cdomsg.Configuration.Fields.Update
lobj_cdomsg.To = sTo
lobj_cdomsg.From = sFrom
lobj_cdomsg.Subject = sSubject
lobj_cdomsg.TextBody = sBody
'lobj_cdomsg.AddAttachment ("filepath")
lobj_cdomsg.Send
Set lobj_cdomsg = Nothing
SendMail = "ok"
Exit Function
SendMail_Error:
SendMail = Err.Description
End Function
-
Feb 28th, 2011, 01:28 PM
#11
Addicted Member
Re: send email with vb6 with smtp
Or you can use smpt:
Code:
Imports System.Net.Mail
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyMailMessage As New MailMessage()
MyMailMessage.From = New MailAddress(TextBox6.Text)
MyMailMessage.To.Add(TextBox1.Text)
MyMailMessage.Subject = TextBox2.Text
MyMailMessage.Body = TextBox3.Text
Dim SMPT As New SmtpClient(ComboBox1.Text)
SMPT.Port = ComboBox2.Text
SMPT.EnableSsl = True
SMPT.Credentials = New System.Net.NetworkCredential(TextBox4.Text, TextBox5.Text)
SMPT.Send(MyMailMessage)
MsgBox("The mail has been send!", MsgBoxStyle.Information, "Mail has been send!")
End Sub
End Class
-
Feb 28th, 2011, 02:27 PM
#12
Thread Starter
Fanatic Member
Re: send email with vb6 with smtp
mitko29
this is not vb.net, its vb6
-
Feb 28th, 2011, 03:24 PM
#13
Addicted Member
Re: send email with vb6 with smtp
 Originally Posted by coolcurrent4u
mitko29
this is not vb.net, its vb6
I am sorry wrong topic.
-
Feb 28th, 2011, 08:47 PM
#14
Re: send email with vb6 with smtp
There are Enums defined already for cdoSMTPAuthenticate (CdoProtocolsAuthentication) and cdoSendUsingMethod (CdoSendUsing), so no need for magic numbers.
-
Mar 1st, 2011, 02:30 AM
#15
Thread Starter
Fanatic Member
Re: send email with vb6 with smtp
dilettante
what do you mean actually, can you please list the enums, thanks?
-
Mar 1st, 2011, 10:52 AM
#16
Re: send email with vb6 with smtp
In line 12 and line 16 above you use 1 and 2. Instead you could use the Enum values cdoBasic and cdoSendUsingPort.
You can easily see these things using the object Browser in the VB6 IDE and they are fully described in the documentation. They are, like most Const and Enum values, meant to be used in order to make your programs easier to maintain because a person reading these programs can tell what is being done (without having to go run to the documentation themselves to look up every line of code used).
-
Mar 1st, 2011, 02:13 PM
#17
Thread Starter
Fanatic Member
Re: send email with vb6 with smtp
-
Mar 1st, 2011, 02:52 PM
#18
Re: send email with vb6 with smtp
Why don't you create a simple .net class that sends the mail, something like mitko29 showed. Call that code from vb6 use [Comvisible] in .net. So you have all code of you're own
-
Mar 2nd, 2011, 07:58 AM
#19
Thread Starter
Fanatic Member
Re: send email with vb6 with smtp
the thing is tha if i use .net, then i need .net libraries to use the program. That is the reason i still develop in vb6. what if my user does not have internet connection to download .net library?
-
Mar 2nd, 2011, 09:53 AM
#20
Addicted Member
Re: send email with vb6 with smtp
wow.........
You always can make a installer for your application and then to include in it the .net framework you need.
I will tell you something about visual basic 6 too :
The program language was made many years ago, and if you want to keep the good work with all programing stuff you have to evolve into c# or vb.net,maybe the syntax is a little strange at the beginning but you will get used.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|