• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

student needs help

I'm still studying at school, and I want to create an executable that will e-mail a specific file to a pre-determined list of e-mail.  All I need is--> how can I send the file to a     e-mail account, I really have no clue as how to do it, I only need help for this part of my program...how do I code to make the file "c:.../.../... .txt" go to this e-mail address without me doing anything.  I only need a bit of code to get me started.
                       thanx in advance.

                    Thanx in advance.
1 Solution
there is a RFC for SMTP.
I have a sample that is all of 5 lines long.
for a single mailing.
It would be simple to add a for loop
which part do you need?
the SMTP is REALLY easy using winsock.ocx
There is a sample of VB and e-mail in the VB samples directory which is normally installed in VB\Samples\CompTool\VBMail  I have a sample of attaching a file to an e-mail and sending it at work, but I wont be able to send it until Monday.

It works by signing on to your MAPI session (of Windows it's sometimes Outlook) and sending the message through your MAPI compliant e-mail system.
This will work very well but it requires that you have a:    DSSocket    Sockets control

You can goto this website and download a shareware?? version of this control.

These are the definitions of the variables being used.  

DSSocket -- Sockets control

lBlockSize -- The maximum size of the file after being split up for more accurate sending
From -- Sender's email address

To -- Recipient's email address

Subject -- Subject of the message

szText -- Any text you want to tag on
to the top of the message.

 Dim nMsgFile    As Integer
 Dim szLine      As String
 Dim szBuffer    As String

On Error GoTo nSendFileAsMsg_Error
If lBlockSize = 0 Then
   lBlockSize = 8192
End If
'-- Open the message file
nMsgFile = FreeFile
Open szFileName For Binary As  nMsgFile
    '-- szBuffer holds up to <blocksize> number of bytes
    '   and is sent when it becomes full.
    '-- Send the header first
    szBuffer = "DATE: " & Format$(Now, "dd mmm yy ttttt") & vbCrLf _
        & "FROM: " & From & vbCrLf _
        & "TO: " & To & vbCrLf _
        & "SUBJECT: " & Subject & vbCrLf & vbCrLf _
        & szText & vbCrLf
    SendData DSSocket, szBuffer
'-- Send the file in segments
Do Until EOF(nMsgFile)
    szBuffer = Space$(lBlockSize)
    Get #nMsgFile, , szBuffer
    SendData DSSocket, szBuffer
Close nMsgFile
'-- Send the final period.
SendData DSSocket, vbCrLf & "." & vbCrLf
    nSendFileAsMsg = Err
    On Error Resume Next
    Close nMsgFile

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now