Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sending files threw e-mail using mswinsock.ocx

Posted on 2000-04-06
8
Medium Priority
?
280 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 8 total points
ID: 2710014
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

782 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