By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

how attach text file with e-mail ?

P: 36
hi for every one

i have program using to send e-mail but i want to attach text file with that
e-mail .

how attach text file with e-mail automatically ?

example :

every time send e-mail i want attach text file example : c:\xx.txt .

thank you .
Apr 23 '07 #1
Share this Question
Share on Google+
3 Replies


P: 36
i use following program to send e-mail but i want to attach file with message :

Expand|Select|Wrap|Line Numbers
  1. Dim Response As String, Reply As Integer, DateNow As String
  2. Dim first As String, Second As String, Third As String
  3. Dim Fourth As String, Fifth As String, Sixth As String
  4. Dim Seventh As String, Eighth As String
  5. Dim Start As Single, Tmr As Single
  6.  
  7.  
  8.  
  9. Sub SendEmail(MailServerName As String, FromName As String, FromEmailAddress As String, ToName As String, ToEmailAddress As String, EmailSubject As String, EmailBodyOfMessage As String)
  10. On Error Resume Next
  11.     Winsock1.LocalPort = 0 ' Must set local port to 0 (Zero) or you can only send 1 e-mail pre program start
  12.  
  13. If Winsock1.State = sckClosed Then ' Check to see if socet is closed
  14.     DateNow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
  15.     first = "mail from:" + Chr(32) + FromEmailAddress + vbCrLf ' Get who's sending E-Mail address
  16.     Second = "rcpt to:" + Chr(32) + ToEmailAddress + vbCrLf ' Get who mail is going to
  17.     Third = "Date:" + Chr(32) + DateNow + vbCrLf ' Date when being sent
  18.     Fourth = "From:" + Chr(32) + FromName + vbCrLf ' Who's Sending
  19.     Fifth = "To:" + Chr(32) + ToNametxt + vbCrLf ' Who it going to
  20.     Sixth = "Subject:" + Chr(32) + EmailSubject + vbCrLf ' Subject of E-Mail
  21.     Seventh = EmailBodyOfMessage + vbCrLf ' E-mail message body
  22.     Ninth = "X-Mailer: EBT Reporter v 2.x" + vbCrLf ' What program sent the e-mail, customize this
  23.     Eighth = Fourth + Third + Ninth + Fifth + Sixth  ' Combine for proper SMTP sending
  24.  
  25.     Winsock1.Protocol = sckTCPProtocol ' Set protocol for sending
  26.     Winsock1.RemoteHost = MailServerName ' Set the server address
  27.     Winsock1.RemotePort = 25 ' Set the SMTP Port
  28.     Winsock1.Connect ' Start connection
  29.  
  30.     WaitFor ("220")
  31.  
  32.     StatusTxt.Caption = "Connecting...."
  33.     StatusTxt.Refresh
  34.  
  35.     Winsock1.SendData ("HELO worldcomputers.com" + vbCrLf)
  36.  
  37.     WaitFor ("250")
  38.  
  39.     StatusTxt.Caption = "Connected"
  40.     StatusTxt.Refresh
  41.  
  42.     Winsock1.SendData (first)
  43.  
  44.     StatusTxt.Caption = "Sending Message"
  45.     StatusTxt.Refresh
  46.  
  47.     WaitFor ("250")
  48.  
  49.     Winsock1.SendData (Second)
  50.  
  51.     WaitFor ("250")
  52.  
  53.     Winsock1.SendData ("data" + vbCrLf)
  54.  
  55.     WaitFor ("354")
  56.  
  57.  
  58.     Winsock1.SendData (Eighth + vbCrLf)
  59.     Winsock1.SendData (Seventh + vbCrLf)
  60.     Winsock1.SendData ("." + vbCrLf)
  61.  
  62.     WaitFor ("250")
  63.  
  64.     Winsock1.SendData ("quit" + vbCrLf)
  65.  
  66.     StatusTxt.Caption = "Disconnecting"
  67.     StatusTxt.Refresh
  68.  
  69.     WaitFor ("221")
  70.  
  71.     Winsock1.Close
  72. Else
  73.     MsgBox (Str(Winsock1.State))
  74. End If
  75.  
  76. End Sub
  77. Sub WaitFor(ResponseCode As String)
  78. On Error Resume Next
  79.  
  80.     Start = Timer ' Time event so won't get stuck in loop
  81.     While Len(Response) = 0
  82.         Tmr = Start - Timer
  83.         DoEvents ' Let System keep checking for incoming response **IMPORTANT**
  84.         If Tmr > 50 Then ' Time in seconds to wait
  85.             MsgBox "SMTP service error, timed out while waiting for response", 64, MsgTitle
  86.             Exit Sub
  87.         End If
  88.     Wend
  89.     While Left(Response, 3) <> ResponseCode
  90.         DoEvents
  91.         If Tmr > 50 Then
  92.             MsgBox "SMTP service error, impromper response code. Code should have been: " + ResponseCode + " Code recieved: " + Response, 64, MsgTitle
  93.             Exit Sub
  94.         End If
  95.     Wend
  96. Response = "" ' Sent response code to blank **IMPORTANT**
  97. End Sub
  98.  
  99.  
  100. Private Sub Command1_Click()
  101. On Error Resume Next
  102.  
  103.     SendEmail txtEmailServer.Text, txtFromName.Text, txtFromEmailAddress.Text, txtToEmailAddress.Text, txtToEmailAddress.Text, txtEmailSubject.Text, txtEmailBodyOfMessage.Text
  104.     'MsgBox ("Mail Sent")
  105.     StatusTxt.Caption = "Mail Sent"
  106.     StatusTxt.Refresh
  107.  
  108.     Close
  109.  
  110. End Sub
  111.  
  112. Private Sub Command2_Click()
  113. End
  114. End Sub
  115.  
  116.  
  117. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  118.  
  119. On Error Resume Next
  120. Winsock1.GetData Response ' Check for incoming response *IMPORTANT*
  121. End Sub
Apr 24 '07 #2

P: 11
Hi,
I have a function that we use to send email via Microsoft email outlook..might help you.
Function fnSendMail(strAttachmentFile, strToAddress, strSubject, strBody)
Set objOutlook = CreateObject("Outlook.Application")
Set objItem = objOutlook.CreateItem(0)
objItem.Attachments.Add strAttachmentFile
arrAddressArray = Split(strToAddress, ";")
strAddress = ""
For intAddCount = 0 To UBound(arrAddressArray)
If InStr(arrAddressArray(intAddCount), "@") <> 0 Then
If StrComp(strAddress, "") <> 0 Then
strAddress = strAddress & ";" & arrAddressArray(intAddCount)
Else
strAddress = arrAddressArray(intAddCount)
End If
End If
Next
objItem.To = strAddress
objItem.Subject = strSubject
objItem.Body = strBody
objItem.Display
objItem.Send
End Function
Apr 24 '07 #3

P: 36
Hi,
I have a function that we use to send email via Microsoft email outlook..might help you.
Function fnSendMail(strAttachmentFile, strToAddress, strSubject, strBody)
Set objOutlook = CreateObject("Outlook.Application")
Set objItem = objOutlook.CreateItem(0)
objItem.Attachments.Add strAttachmentFile
arrAddressArray = Split(strToAddress, ";")
strAddress = ""
For intAddCount = 0 To UBound(arrAddressArray)
If InStr(arrAddressArray(intAddCount), "@") <> 0 Then
If StrComp(strAddress, "") <> 0 Then
strAddress = strAddress & ";" & arrAddressArray(intAddCount)
Else
strAddress = arrAddressArray(intAddCount)
End If
End If
Next
objItem.To = strAddress
objItem.Subject = strSubject
objItem.Body = strBody
objItem.Display
objItem.Send
End Function
thank you but i do not use outlook

i want to attach file with my program that posted in here .
Apr 25 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.