Solved

sending files threw e-mail using mswinsock.ocx

Posted on 2000-04-06
8
261 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
 

Author Comment

by:johnnyeses
ID: 2692415
whats "Outlook"?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now