473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

how attach text file with e-mail ?

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
3 2235
mse07
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
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
mse07
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

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

Similar topics

3
by: Aymer | last post by:
i created a new button object. how do i attach an event on it? thanx for your help. Dim cc As ColorConverter = new ColorConverter() Dim b = new button() b.ID = "SelectedDate" b.BorderStyle...
15
by: tabonni | last post by:
Hi I try to grab the checked files from HTML page and then send those PDF files as attachments. It can just send email, there are no PDF files attached. Can anybody point out my error? My...
1
by: RickL | last post by:
How do you attach a file to a hyperlink so that it cab be opened when clicked? I am new to .net and web development and I need to attach a file to an asp page so that when click it can be opened it...
1
by: kevcar40 | last post by:
i have a form that i want to attach files to as hyperlinks the problem is there could be upto 10 files attached to the form or maybe none How can i go about 1 creating the attachements and...
7
by: Greg P | last post by:
I know this is a long post, please bear with me. I have been working on this all weekend to no avail although I have done a good amount of research (see most pertinent links that I've looked at...
2
by: calebmichaud | last post by:
Hi I am having trouble understanding how to attach a file or files to a record. I want to (in form view0 allow the user to attach one or more than one file to the associated record, and then...
5
by: Kees de Winter | last post by:
Is it possible to attach the VS2005 debugger to an already running, and published website? If I choose "Attach to process" from the menu and then select the right process, set breakpoints, run the...
0
by: Lexxzy | last post by:
Hi to all, I've a problem about to attach a recovered database file in the enterprise manager. My problem goes this way, I want to attach a recovered database file. So when I followed this...
14
by: sreemathy2000 | last post by:
My requirement is to generate and attach a file and send in an email automatically. i have a existing functionality where i using the code below to write a CSV file in my local system. ...
9
by: dpatel75 | last post by:
I am trying to copy a database from a SQL 2000 SP3 Windows 2000 server to a 2005 SP2 Windows 2003 server. I am trying to use detach and attach method (have tried both within Management Studio and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.