home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / findfile / sendbug.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-28  |  8.7 KB  |  263 lines

  1. VERSION 5.00
  2. Begin VB.Form Form7 
  3.    Appearance      =   0  '2D
  4.    BackColor       =   &H00808080&
  5.    BorderStyle     =   0  'Kein
  6.    Caption         =   "Send Bug Report"
  7.    ClientHeight    =   3192
  8.    ClientLeft      =   0
  9.    ClientTop       =   0
  10.    ClientWidth     =   4680
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   3192
  15.    ScaleWidth      =   4680
  16.    StartUpPosition =   2  'Bildschirmmitte
  17.    Begin VB.TextBox DataArrival 
  18.       Appearance      =   0  '2D
  19.       Height          =   288
  20.       Left            =   960
  21.       TabIndex        =   3
  22.       Text            =   "Text1"
  23.       Top             =   2760
  24.       Visible         =   0   'False
  25.       Width           =   1212
  26.    End
  27.    Begin VB.CommandButton Exit 
  28.       Appearance      =   0  '2D
  29.       Caption         =   "Exit"
  30.       Height          =   255
  31.       Left            =   2280
  32.       TabIndex        =   2
  33.       Top             =   2880
  34.       Width           =   2295
  35.    End
  36.    Begin VB.CommandButton SendBugConnect 
  37.       Appearance      =   0  '2D
  38.       Caption         =   "Send Feedback"
  39.       Height          =   255
  40.       Left            =   120
  41.       TabIndex        =   1
  42.       Top             =   2880
  43.       Width           =   2055
  44.    End
  45.    Begin VB.TextBox Bugreporttxt 
  46.       Appearance      =   0  '2D
  47.       Height          =   2655
  48.       Left            =   120
  49.       MultiLine       =   -1  'True
  50.       TabIndex        =   0
  51.       Top             =   120
  52.       Width           =   4455
  53.    End
  54. Attribute VB_Name = "Form7"
  55. Attribute VB_GlobalNameSpace = False
  56. Attribute VB_Creatable = False
  57. Attribute VB_PredeclaredId = True
  58. Attribute VB_Exposed = False
  59. '*******************************************
  60. '*New Updates:
  61. '-Api Declarations! (needs no Winsock.ocx)
  62. '-Check if the Server respond with the right code
  63. '-Perform a better error check
  64. '-Use a better timeout routine to check if the Server
  65. 'times out
  66. '*******************************************
  67. Option Explicit
  68. Private bTrans As Boolean
  69. Private m_iStage As Integer
  70. Private Sock As Integer
  71. Private RC As Integer
  72. Private Bytes As Integer
  73. Private ResponseCode As Integer
  74. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  75. 'CHANGE THIS SETTING LIKE YOU NEED IT
  76. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  77. Private Const mailserver As String = "127.0.0.1"
  78. Private Const Tobox As String = "galgen@wtal.de"
  79. Private Const Frombox As String = "theuser@ofthisprogram.com"
  80. Private Const Subject As String = "User Feedback!"
  81. 'This is for the WaitforResponse Routine
  82. Private Declare Function timeGetTime Lib "winmm.dll" () As Long
  83. '***************************************************************
  84. 'Routine for connecting to the server
  85. '***************************************************************
  86. Sub SendBugConnect_Click()
  87. Dim StartupData As WSADataType
  88. Dim SocketBuffer As sockaddr
  89. Dim IpAddr As Long
  90. 'Ini the Winsocket
  91. RC = WSAStartup(&H101, StartupData)
  92. RC = WSAStartup(&H101, StartupData)
  93. 'Open a free Socket (with this source code you can also
  94. 'open several connections! Very useful for E-Mail Applications...)
  95. Sock = socket(AF_INET, SOCK_STREAM, 0)
  96. If Sock = SOCKET_ERROR Then
  97.     MsgBox "Cannot Create Socket."
  98.     Exit Sub
  99. End If
  100. 'Checks if the Hostname exists
  101. If RC = SOCKET_ERROR Then Exit Sub
  102. IpAddr = GetHostByNameAlias(mailserver)
  103. If IpAddr = -1 Then
  104.     MsgBox "Unknown Host: " + mailserver
  105.     Exit Sub
  106. End If
  107. 'This part is responsible for the connection
  108. SocketBuffer.sin_family = AF_INET
  109. SocketBuffer.sin_port = htons(25)
  110. SocketBuffer.sin_addr = IpAddr
  111. SocketBuffer.sin_zero = String$(8, 0)
  112. RC = connect(Sock, SocketBuffer, Len(SocketBuffer))
  113. 'If an error occured close the connection and
  114. 'send an error message to the text window
  115. If RC = SOCKET_ERROR Then
  116.         MsgBox "Cannot Connect to " + mailserver + _
  117.                             Chr$(13) + Chr$(10) + _
  118.                             GetWSAErrorString(WSAGetLastError())
  119.         closesocket Sock
  120.         RC = WSACleanup()
  121.         Exit Sub
  122. End If
  123. 'Select Receive Window
  124. RC = WSAAsyncSelect(Sock, DataArrival.hWnd, _
  125.                         ByVal &H202, ByVal FD_READ Or FD_CLOSE)
  126.     If RC = SOCKET_ERROR Then
  127.         MsgBox "Cannot Process Asynchronously."
  128.         closesocket Sock
  129.         RC = WSACleanup()
  130.         Exit Sub
  131.     End If
  132. bTrans = True
  133. m_iStage = 0
  134. DataArrival = ""
  135. ResponseCode = 220
  136. Call WaitForResponse
  137. End Sub
  138. '***************************************************************
  139. 'Transmit the E-Mail
  140. '***************************************************************
  141. Private Sub Transmit(iStage As Integer)
  142. Dim Helo As String, temp As String
  143. Dim pos As Integer
  144. Select Case m_iStage
  145. Case 1:
  146.     Helo = Frombox
  147.     pos = Len(Helo) - InStr(Helo, "@")
  148.     Helo = Right$(Helo, pos)
  149.     ResponseCode = 250
  150.     WinsockSendData ("HELO " & Helo & vbCrLf)
  151.     Call WaitForResponse
  152. Case 2:
  153.     ResponseCode = 250
  154.     WinsockSendData ("MAIL FROM: <" & Trim(Frombox) & ">" & vbCrLf)
  155.     Call WaitForResponse
  156. Case 3:
  157.     ResponseCode = 250
  158.     WinsockSendData ("RCPT TO: <" & Trim(Tobox) & ">" & vbCrLf)
  159.     Call WaitForResponse
  160. Case 4:
  161.     ResponseCode = 354
  162.     WinsockSendData ("DATA" & vbCrLf)
  163.     Call WaitForResponse
  164. Case 5:
  165. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  166. 'If you want additional Headers like Date,Message-Id,...etc. !
  167. 'simply add them below                                      !
  168. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  169.     temp = temp & "From: " & Frombox & vbNewLine
  170.     temp = temp & "To: " & Tobox & vbNewLine
  171.     temp = temp & "Subject: " & Subject & vbNewLine
  172.     'Header + Message
  173.     temp = temp & vbCrLf & Bugreporttxt.Text
  174.     'Send the Message & close connection
  175.     WinsockSendData (temp)
  176.     WinsockSendData (vbCrLf & "." & vbCrLf)
  177.     ResponseCode = 250
  178.     Call WaitForResponse
  179. Case 6:
  180.     MsgBox "E-Mail was successfuly sended!"
  181.     WinsockSendData ("QUIT" & vbCrLf)
  182.     ResponseCode = 221
  183.     Call WaitForResponse
  184.     m_iStage = 0
  185.     bTrans = False
  186. End Select
  187. End Sub
  188. '***************************************************************
  189. 'Routine for arraving Data
  190. '***************************************************************
  191. Private Sub DataArrival_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  192. Dim MsgBuffer As String * 2048
  193. On Error Resume Next
  194.     If Sock > 0 Then
  195.         'Receive up to 2048 chars
  196.         Bytes = recv(Sock, ByVal MsgBuffer, 2048, 0)
  197.         
  198.         If Bytes > 0 Then
  199.             
  200.                 
  201.         If bTrans Then
  202.             If ResponseCode = Left(MsgBuffer, 3) Then
  203.             MsgBuffer = vbNullString
  204.             m_iStage = m_iStage + 1
  205.             Transmit m_iStage
  206.             Else
  207.                 closesocket (Sock)
  208.                 RC = WSACleanup()
  209.                 Sock = 0
  210.                 MsgBox "The Server responds with an unexpected Response Code!", vbOKOnly, "Error!"
  211.                 Exit Sub
  212.             End If
  213.         End If
  214.         ElseIf WSAGetLastError() <> WSAEWOULDBLOCK Then
  215.             closesocket (Sock)
  216.             RC = WSACleanup()
  217.             Sock = 0
  218.         End If
  219.     End If
  220. Refresh
  221. End Sub
  222. '**************************************************************
  223. ' Waits until time out, while waiting for response
  224. '**************************************************************
  225. Private Sub WaitForResponse()
  226. Dim Start As Long
  227. Dim Tmr As Long
  228. 'Works with an Api Declaration because it's more precious
  229. Start = timeGetTime
  230. While Bytes > 0
  231.     Tmr = timeGetTime - Start
  232.     DoEvents ' Let System keep checking for incoming response
  233.         
  234.     'Wait 50 seconds for response
  235.     If Tmr > 50000 Then
  236.         MsgBox "SMTP service error, timed out while waiting for response", 64, "Error!"
  237.         End
  238.     End If
  239. End Sub
  240. Private Sub WinsockSendData(DatatoSend As String)
  241. Dim RC As Integer
  242. Dim MsgBuffer As String * 2048
  243. MsgBuffer = DatatoSend
  244. RC = send(Sock, ByVal MsgBuffer, Len(DatatoSend), 0)
  245. 'If an error occurs send an error message and
  246. 'reset the winsock
  247. If RC = SOCKET_ERROR Then
  248.     MsgBox "Cannot Send Request." + _
  249.                             Chr$(13) + Chr$(10) + _
  250.                             Str$(WSAGetLastError()) + _
  251.                             GetWSAErrorString(WSAGetLastError())
  252.     closesocket Sock
  253.     RC = WSACleanup()
  254.     Exit Sub
  255. End If
  256. End Sub
  257. Private Sub Exit_Click()
  258. On Error Resume Next
  259.     closesocket Sock
  260.     RC = WSACleanup()
  261.     End
  262. End Sub
  263.