Solved

sending files threw e-mail using mswinsock.ocx

Posted on 2000-04-06
8
269 Views
Last Modified: 2013-11-13
i can send an email fine using the winsock control, but i cannot figure out how to attach a file to the mail. can you please help me with this?
p.s. sorry for the 4 points
0
Comment
Question by:johnnyeses
8 Comments
 
LVL 1

Expert Comment

by:ATM
ID: 2692082
SMTP attachment example can be found at
http://www.tair.freeservers.com/vb/base64.html
p.s. sorry for URL only.
0
 
LVL 1

Expert Comment

by:ATM
ID: 2692083
SMTP attachment example can be found at
http://www.tair.freeservers.com/
p.s. sorry for URL only.
0
 
LVL 30

Expert Comment

by:Axter
ID: 2692177
Function SendAttachedEmail(ToEmailAddress As String, Subject As String, BodyOfEmail As String, CCEmailAddress As String, ConfirmDelivery As Boolean, ConfirmRead As Boolean, CC_ThisMessage As Boolean, AddressOfAttachedMent As String) As Boolean
    Dim olApp As New Outlook.Application
    Dim MyMailItem As Outlook.MailItem
    Set MyMailItem = olApp.CreateItem(olMailItem)
    MyMailItem.To = ToEmailAddress
    MyMailItem.Subject = Subject
    MyMailItem.Body = BodyOfEmail
    If Not IsNull(CCEmailAddress) And Len(CCEmailAddress) > 0 Then MyMailItem.CC = CCEmailAddress
    If ConfirmDelivery = True Or ConfirmRead = True Then MyMailItem.OriginatorDeliveryReportRequested = True
    If Not IsNull(AddressOfAttachedMent) And Len(AddressOfAttachedMent) > 0 Then
        MyMailItem.Attachments.Add AddressOfAttachedMent, olByValue, 1, AddressOfAttachedMent
    End If
    Dim fdInbox As Outlook.MAPIFolder
    Dim nsMAPI As Outlook.NameSpace
    Set nsMAPI = olApp.GetNamespace("MAPI")
    Set fdInbox = nsMAPI.GetDefaultFolder(olFolderInbox)
    Dim exp As Outlook.Explorer
    If exp Is Nothing Then
        Set exp = fdInbox.GetExplorer
    Else
        Set exp.CurrentFolder = fdInbox
    End If
    MyMailItem.Save
    MyMailItem.Send
    SendAttachedEmail = True
End Function

0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:johnnyeses
ID: 2692415
whats "Outlook"?
0
 

Expert Comment

by:Slightly_Imperfect
ID: 2692704
I use a mapi control to send email with attachments!!  all you need to do is add MAPI controls on your form in components!!! and apply this code

 MAPISess1.DownLoadMail = False
           MAPISess1.LogonUI = False
           MAPISess1.Action = SESSION_SIGNON
           MAPIMess1.SessionID = MAPISess1.SessionID
           MAPIMess1.Compose
           MAPIMess1.MsgIndex = -1
           MAPIMess1.RecipType = 1
           MAPIMess1.RecipDisplayName = "michael_oconner@clearwater-consulting.co.uk"
           MAPIMess1.AddressResolveUI = False
           MAPIMess1.ResolveName
           MAPIMess1.MsgSubject = "Ellis and Everard weekly events email"
           MAPIMess1.MsgNoteText = Space(6) & vbCrLf & _
           "This Document contains Events that have Occured at Ellis and" & vbCrLf & _
           "In the previous Month"
              With MAPIMess1
               .AttachmentIndex = 0
               .AttachmentPosition = 0
               .AttachmentPathName = ("c:\download\ellis.doc")
               If attached_flag = True Then
                 .AttachmentIndex = 1
                 .AttachmentPosition = 1
                 .AttachmentPathName = ("c:\download\eande\monthly\" + Month_Name + "_changes.doc")
               End If
               End With
            MAPIMess1.Send False
            MAPISess1.Action = SESSION_SIGNOFF
            MAPISess1.DownLoadMail = True
            MAPISess1.Action = SESSION_SIGNON
            MAPISess1.Action = SESSION_SIGNOFF
            frmEmail.Text1 = frmEmail.Text1 + "Monthly Ellis & Everade report was sent at " & Format(Now, "long time") + Chr(13) + Chr(10)
            document_exists = True


Here are the variables i used !!!
Const SESSION_SIGNOFF = 2
Const SESSION_SIGNON = 1
Const RECIPTYPE_NO = 1
Const MESSAGE_COMPOSE = 6
Const MESSAGE_SEND = 3
Const MESSAGE_RESOLVENAME = 13



You will need to have microsoft Outlook set up and open but this code works no problems. Every time you want to add a new attachment


                 .AttachmentIndex = 1
                 .AttachmentPosition = 1
                 .AttachmentPathName = ("c:\download\eande\monthly\" + Month_Name + "_changes.doc")

increment the index and position by one!!! oh and change the space(6)

Hope this helps!!!

0
 
LVL 1

Expert Comment

by:ATM
ID: 2692740
Here is attachment MIME example:

             outBuffer = outBuffer & "From: ATM" & Chr(13) & Chr(10)
             outBuffer = outBuffer & "To: EXEX" & Chr(13) & Chr(10)
             outBuffer = outBuffer & "Subject: " & Subject_Text & Chr(13) & Chr(10)
             outBuffer = outBuffer & "MIME-Version: 1.0" & Chr(13) & Chr(10)

           If Attach_File_Name <> "" Then
             outBuffer = outBuffer & "Content-Type: multipart/mixed;" & Chr(13) & Chr(10)
             outBuffer = outBuffer & "              boundary=tair_iyi_cocuktur_lo_00023" & Chr(13) & Chr(10)
             outBuffer = outBuffer & Chr(13) & Chr(10)
             outBuffer = outBuffer & "This is a multi-part message in MIME format." & Chr(13) & Chr(10)
             outBuffer = outBuffer & Chr(13) & Chr(10)
             outBuffer = outBuffer & "--tair_iyi_cocuktur_lo_00023" & Chr(13) & Chr(10)
           End If

              outBuffer = outBuffer & "Content-Type: text/html" & Chr(13) & Chr(10)
              outBuffer = outBuffer & Chr(13) & Chr(10)
              outBuffer = outBuffer & mail_Body & Chr(13) & Chr(10) & Chr(13) & Chr(10)
              WS_SMTP.SendData outBuffer
              outBuffer = ""

           If Attach_File_Name <> "" Then
              outBuffer = outBuffer & "--tair_iyi_cocuktur_lo_00023" & Chr(13) & Chr(10)
              outBuffer = outBuffer & "Content-Type: application/octet-stream;" & Chr(13) & Chr(10)
              outBuffer = outBuffer & "    Name=" & Attach_File_Name & Chr(13) & Chr(10)
              outBuffer = outBuffer & "Content-Disposition: attachment;" & Chr(13) & Chr(10)
              outBuffer = outBuffer & "    FileName=" & Attach_File_Name & Chr(13) & Chr(10) & Chr(13) & Chr(10)
             For zu = 0 To Attach_length - 1
              outBuffer = outBuffer & Chr(Attach_File(zu))
             Next
              outBuffer = outBuffer & Chr(13) & Chr(10) & Chr(13) & Chr(10)
              outBuffer = outBuffer & "--tair_iyi_cocuktur_lo_00023"
            End If
              outBuffer = outBuffer & Chr(13) & Chr(10) & "." & Chr(13) & Chr(10)
              WS_SMTP.SendData outBuffer
         End If

Attach_File(zu) is a string array include Your file bytes. Bytes which You load from file ...
0
 

Author Comment

by:johnnyeses
ID: 2694166
im not very good at vb as u can tell. how do i load the file bytes, and how do i get the attach_length?
thx
0
 
LVL 1

Accepted Solution

by:
adam8 earned 4 total points
ID: 2710014
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question