Solved

sending files threw e-mail using mswinsock.ocx

Posted on 2000-04-06
8
270 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
message box in access 4 51
Recommendation vb6 to vb.net or others 14 175
Problem to With line 4 63
pop out of webbrowser1 control vba6 5 25
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

861 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