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 5231
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: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |