Can anyone point me in the right direction here?
As part of a database I'm designing, it has to be able to connect to an SMTP server. I know how to go about the protocol once connected, I know the hostname and port, I just don't know how to connect in the first place.
All I need to know is:
1. What object type allows me to make this connection? And what references do I need to be able to do this?
2. How do I open a connection, send to the server, read from the server, and close?
Thank-you in advance.
4 5233
Can anyone point me in the right direction here?
As part of a database I'm designing, it has to be able to connect to an SMTP server. I know how to go about the protocol once connected, I know the hostname and port, I just don't know how to connect in the first place. In addition I store the name of the SMTP server in a one line configtable in the frontend database in case the smtp servername changes and I don't want to revisit my code meely for this
All I need to know is:
1. What object type allows me to make this connection? And what references do I need to be able to do this?
2. How do I open a connection, send to the server, read from the server, and close?
Thank-you in advance.
Set a reference to Microsoft CDO for Windows 2000 Library
Here is a fully tested Function that I use for one of my production systems where parameters are passed in which includes a concatenated list of file attachments from a pop up dialog Access form resembling the usual outlook form. The form itself uses the usual automation techniques in order to retrieve outlook folders,users email addresses etc but which DOESNT use outlook to send the mail message instead favouring simple SMTP direct server access for sending the message but with a 'copy' returning back into outlook (their standard mail client for proof of sending... they didnt want to get into trying to byepass the security SP2 annoying popup message and didnt want to use ClickYes PRO small third party app either :)
Just remove the lines where I am calling in the function PLEASEWAIT This is merely a floating pop I use to relay information to the user as to the status of action in the send process so that they know whats going on (you might want to keep something like that in yours? thats why I left the lines in... whatever.) I don't know whether you have your own method for that but if you want the function let me know.
I also lookup the string value of the SMTP server name from a one line config table in case the server name changes in future and I don't want to revisit my code just for that. The value of which is editable from the usual dialog setup screens I tend to supply for variable system config stuff. - Public Function SendCDOMail(ByVal strFrom As String, ByVal strTo As String, intPerID, ByVal strSubject As String, ByVal strBody As String, strAttachmentPath As String) As Boolean
-
On Error GoTo Err_SendCDOMail
-
If Trim$(strFrom) = "" Then
-
MsgBox "No email for the sender portion has been specified", vbExclamation, "Send Mail"
-
SendCDOMail = False
-
Exit Function
-
End If
-
If Trim$(strTo) = "" Then
-
MsgBox "No recipient email address has been specified", vbExclamation, "Send Mail"
-
SendCDOMail = False
-
Exit Function
-
End If
-
If Trim$(strSubject) = "" Then
-
MsgBox "No subject heading for the email was retrieved!", vbExclamation, "Send Mail"
-
SendCDOMail = False
-
Exit Function
-
End If
-
If Trim$(strBody) = "" Then
-
MsgBox "No text body for the email was retrieved!", vbExclamation, "Send Mail"
-
SendCDOMail = False
-
Exit Function
-
End If
-
-
Dim iCfg As CDO.Configuration
-
Dim iMsg As CDO.Message
-
Dim mailserver As String
-
mailserver = DLookup("[SMTPServerName]", "Usys_tblConfigLocal")
-
-
Set iCfg = New CDO.Configuration
-
PleaseWait ("Setting up email connection using C.D.O protocol...")
-
With iCfg
-
.Fields(cdoSMTPServer) = mailserver
-
.Fields(cdoSMTPServerPort) = 25 ' typically
-
.Fields(cdoSendUsingMethod) = cdoSendUsingPort
-
.Fields(cdoSMTPConnectionTimeout) = 200
-
.Fields.Update
-
End With
-
-
Set iMsg = New CDO.Message
-
With iMsg
-
Set .Configuration = iCfg
-
.From = ""
-
.Sender = strFrom
-
.ReplyTo = strFrom
-
.Subject = strSubject
-
.TextBody = strBody
-
.To = strTo
-
.CC = strFrom
-
If strAttachmentPath <> "" Then
-
PleaseWait ("Gathering file attachments...")
-
Dim Count As Integer, f() As String, i As Integer, FileName As String, myfiles As String
-
Erase f
-
FileName = Dir(strAttachmentPath, vbNormal + vbHidden + vbSystem) ' Get first file name.
-
'objEmail.Attachments.Add FileName
-
'Iterate through PATH, caching all files in F()
-
Do While FileName <> ""
-
-
If FileName <> "." And FileName <> ".." Then
-
If (GetAttr(strAttachmentPath + FileName) And vbDirectory) <> vbDirectory Then
-
If err <> 53 And err <> 76 Then
-
If (Count Mod 10) = 0 Then
-
ReDim Preserve f(Count + 10) ' Resize the array.
-
End If
-
Count = Count + 1 ' Increment counter.
-
f(Count) = FileName
-
PleaseWait ("Retrieving filenames..." & FileName)
-
End If
-
End If
-
End If
-
-
-
.AddAttachment strAttachmentPath + FileName
-
FileName = Dir ' Get another file name.
-
Loop
-
End If
-
PleaseWait ("Sending " & strSubject & " email please be patient. I am communicating with the server. You will be informed of the result...")
-
.Send
-
End With
-
msg = "Message Sent!" & vbCrLf & vbCrLf
-
msg = msg & "A copy of this email has been sent (CC'd)" & vbCrlf
-
msg = msg & "to your email inbox as proof of sending"
-
MsgBox msg, vbInformation, "Application Name Email Message"
-
On Error Resume Next
-
-
-
SendCDOMail = True
-
Set iMsg = Nothing
-
Set iCfg = Nothing
-
PleaseWait ("")
-
Exit_SendCDOMail:
-
Exit Function
-
-
Err_SendCDOMail:
-
PleaseWait ("")
-
Set iMsg = Nothing
-
Set iCfg = Nothing
-
SendCDOMail = False
-
MsgBox err.Description, vbInformation, "SendCDOMail Function error Command Cancelled"
-
Resume Exit_SendCDOMail
-
-
End Function
Regards
Jim
That's brilliant mate, and a lot more than I expected!
Thank-you.
Ignore me, just subscribing :-)
Regards,
Scott
That's brilliant mate, and a lot more than I expected!
Thank-you.
You're welcome
Jim
Sign in to post your reply or Sign up for a free account.
Similar topics
by: pyguy2 |
last post by:
Issues of socket programming can be wierd, so I'm looking for some
comments.
In my python books I find exclusive use of socket.close(). From my
other readings, I know about a "partial close...
|
by: John Sheppard |
last post by:
Hi all,
I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
|
by: John Sheppard |
last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand.
Programming environment. VS.NET 2003, C#, Windows...
|
by: mscirri |
last post by:
The code below is what I am using to asynchronously get data from a
PocketPC device. The data comes in fine in blocks of 1024 bytes but
even when I send no data from the PocketPC constant blocks of...
|
by: djc |
last post by:
I read a network programming book (based on framework 1.1) which indicated
that you should 'never' use the RecieveTimeout or the SendTimeout 'socket
options' on TCP sockets or you may loose data. I...
|
by: Uma - Chellasoft |
last post by:
Hai,
I am new to VB.Net programming, directly doing socket programming. In C, I
will be able to map the message arrived in a socket directly to a structure.
Is this possible in VB.Net. Can...
|
by: atlaste |
last post by:
Hi,
In an attempt to create a full-blown webcrawler I've found myself
writing a wrapper around the Socket class in an attempt to make it
completely async, supporting timeouts and some scheduling...
|
by: shonen |
last post by:
I'm currently attempting to connect to a shoutcast server
pull down the information from here and then I'll parse it.
I got this working with the httplib, which was great, the problem is I want...
|
by: =?Utf-8?B?Sm9obg==?= |
last post by:
Hi all,
I am new to .net technologies.
ASP.NET supports socket programming like send/receive in c or c++?
I am developing web-site application in asp.net and code behind is Visual
C#. In...
|
by: Stuart |
last post by:
I am in the process of teaching myself socket programming. I am
"playing around" with
some simple echo server-client programs for m the book TCP/IP Sockets
in C.
The Server program is:
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |