Solved

sending files threw e-mail using mswinsock.ocx

Posted on 2000-04-06
8
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

749 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