Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
GostMail - smtp.frm

smtp.frm

Caricato da: Natamas
Scarica il programma completo

  1. Dim StrIn As String, percorso As String, cont1 As Long, cont2 As Long, tip As Byte, reg As String
  2. Dim OKToSend As Boolean
  3. Dim strdata As String, pos As Long, versione As String
  4.  
  5. Private Sub attcomand_Click()
  6. Dialog.ShowOpen
  7. If Dialog.FileName <> "" And Dir(Dialog.FileName) <> "" Then
  8. TxtLogo.Text = Dialog.FileName
  9. Else
  10. MsgBox "Non hai selezionato nessun file, riprovare!", vbExclamation, App.Title
  11. TxtLogo.Text = ""
  12. Dialog.FileName = ""
  13. Exit Sub
  14. End If
  15. End Sub
  16.  
  17. Private Sub Command2_Click()
  18. If txtSMTP.Text <> "" And Recipient.Text <> "" And txtEMail.Text <> "" And txtSender.Text <> "" And txtSubject.Text <> "" And testo.Text <> "" Then
  19. pos = 1
  20. Command2.Enabled = False
  21. Load WS(1)
  22.      a% = MailTo(txtSMTP.Text, txtSubject.Text, txtSender.Text, txtEMail.Text, Recipient.Text, testo.Text, TxtLogo.Text)
  23. Unload WS(1)
  24.      If a% <> 0 Then
  25.         MsgBox "Errore durante la spedizione della email", vbCritical, App.Title & "  -  Errore"
  26.      Else
  27.         Call deletetemp
  28.         MsgBox "Email inviata con successo!", vbInformation, App.Title
  29.      End If
  30. Command2.Enabled = True
  31. Else
  32. MsgBox "Solo il campo " & Chr(34) & "Allegato" & Chr(34) & " e facoltativo, tutti gli altri sono obbligatori", vbExclamation, App.Title
  33. End If
  34. End Sub
  35.  
  36. Private Sub exp_g_Click()
  37. tip = 1
  38. Timer2.Enabled = True
  39. End Sub
  40.  
  41. Private Sub exp_s_Click()
  42. tip = 2
  43. Timer2.Enabled = True
  44. End Sub
  45.  
  46. Private Sub Form_Load()
  47. cont1 = 6360
  48. cont2 = 8280
  49. versione = App.Major & "." & App.Minor & "." & App.Revision
  50. Caption = App.Title & "   -   " & App.LegalCopyright
  51. reg = GetSetting("GM", versione, "Heigh")
  52. If reg <> "" Then
  53. Me.Height = reg
  54. Else
  55. SaveSetting "GM", versione, "Heigh", cont1
  56. Me.Height = cont1
  57. End If
  58. txtSMTP.Text = "mail.libero.it"
  59. If Me.Height = 6360 Then
  60. exp_g.Enabled = True
  61. exp_s.Enabled = False
  62. tip = 1
  63. ElseIf Me.Height = 8280 Then
  64. exp_g.Enabled = False
  65. exp_s.Enabled = True
  66. tip = 2
  67. End If
  68. End Sub
  69. Private Sub Form_Unload(Cancel As Integer)
  70. Dim hg As Long
  71. If Me.Height > cont1 Then
  72. SaveSetting "GM", versione, "Heigh", cont2
  73. Else
  74. SaveSetting "GM", versione, "Heigh", cont1
  75. End If
  76. Unload Me
  77. End
  78. End Sub
  79.  
  80. Private Sub info_Click()
  81. frmAbout.Show 1
  82. End Sub
  83.  
  84. Private Sub Label6_Click()
  85. If Dialog.FileName <> "" Then
  86. TxtLogo.Text = ""
  87. Dialog.FileName = ""
  88. MsgBox "Allegato eliminato !", vbInformation, App.Title
  89. Else
  90. MsgBox "Non esiste nessun allegato !", vbExclamation, App.Title
  91. End If
  92. End Sub
  93.  
  94. Private Sub Label6_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  95. Label6.ForeColor = &HFF&
  96. Timer1.Enabled = True
  97. End Sub
  98.  
  99. Private Sub Recipient_GotFocus()
  100. If Recipient.Text = "destinatario@email.it" Then Recipient.Text = ""
  101. Recipient.BackColor = vbYellow
  102. End Sub
  103.  
  104. Private Sub Recipient_LostFocus()
  105. Recipient.BackColor = vbWhite
  106. Recipient.Text = LCase$(Trim$(Recipient.Text))
  107. End Sub
  108.  
  109. Private Sub testo_GotFocus()
  110. testo.BackColor = vbYellow
  111. End Sub
  112.  
  113. Private Sub testo_LostFocus()
  114. testo.BackColor = vbWhite
  115. End Sub
  116.  
  117. Private Sub Timer1_Timer()
  118. If Label6.ForeColor = &HFF& Then
  119. Label6.ForeColor = &H0&
  120. End If
  121. Timer1.Enabled = False
  122. End Sub
  123.  
  124. Private Sub Timer2_Timer()
  125. If tip = 1 Then
  126. If Me.Height < cont2 Then
  127. Me.Height = Me.Height + 10
  128. Else
  129. exp_g.Enabled = False
  130. exp_s.Enabled = True
  131. Timer2.Enabled = False
  132. End If
  133. ElseIf tip = 2 Then
  134. If Me.Height > cont1 Then
  135. Me.Height = Me.Height - 10
  136. Else
  137. exp_g.Enabled = True
  138. exp_s.Enabled = False
  139. Timer2.Enabled = False
  140. End If
  141. End If
  142. End Sub
  143.  
  144. Private Sub txtEMail_GotFocus()
  145. If txtEMail.Text = "tua e-mail@server.it" Then txtEMail.Text = ""
  146. txtEMail.BackColor = vbYellow
  147. End Sub
  148.  
  149. Private Sub txtEMail_LostFocus()
  150. txtEMail.BackColor = vbWhite
  151. txtEMail.Text = LCase$(Trim$(txtEMail.Text))
  152. End Sub
  153.  
  154. Private Sub TxtLogo_GotFocus()
  155. TxtLogo.BackColor = vbYellow
  156. End Sub
  157.  
  158. Private Sub TxtLogo_LostFocus()
  159. TxtLogo.BackColor = vbWhite
  160. TxtLogo.Text = Trim$(TxtLogo.Text)
  161. End Sub
  162.  
  163. Private Sub txtSender_GotFocus()
  164. If txtSender.Text = "Tuo nome" Then txtSender.Text = ""
  165. txtSender.BackColor = vbYellow
  166. End Sub
  167.  
  168. Private Sub txtSender_LostFocus()
  169. txtSender.BackColor = vbWhite
  170. txtSender.Text = Trim$(txtSender.Text)
  171. End Sub
  172.  
  173. Private Sub txtSMTP_GotFocus()
  174. txtSMTP.BackColor = vbYellow
  175. End Sub
  176.  
  177. Private Sub txtSMTP_LostFocus()
  178. txtSMTP.BackColor = vbWhite
  179. txtSMTP.Text = LCase$(Trim$(txtSMTP.Text))
  180. End Sub
  181.  
  182. Private Sub txtSubject_GotFocus()
  183. txtSubject.BackColor = vbYellow
  184. End Sub
  185.  
  186. Private Sub txtSubject_LostFocus()
  187. txtSubject.BackColor = vbWhite
  188. txtSubject.Text = Trim$(txtSubject.Text)
  189. End Sub
  190.  
  191. Private Sub WS_DataArrival(Index As Integer, ByVal bytesTotal As Long)
  192.  WS(1).GetData strdata, vbString
  193.  'visualizza informazioni di debug (si puo' anche eliminare)
  194.  Text1.Text = Text1.Text + strdata
  195.  Text1.SelStart = Len(Text1.Text) - 1
  196. End Sub
  197.  
  198. Function getreply(Reply As String) As Integer
  199. 'attende una risposta dal server, terminata con CR e/o LF
  200.  t# = Timer
  201.  While Timer < t# + 5 And InStr(strdata, Chr$(13)) = 0 And InStr(strdata, Chr$(10)) = 0
  202.   DoEvents
  203.  Wend
  204.  valid = False
  205.  If InStr(strdata, Chr$(13)) Then
  206.   strdata = Left$(strdata, InStr(strdata, Chr$(13)) - 1)
  207.   valid = True
  208.  End If
  209.  If InStr(strdata, Chr$(10)) Then
  210.   strdata = Left$(strdata, InStr(strdata, Chr$(10)) - 1)
  211.   valid = True
  212.  End If
  213.  If valid Then
  214. 'se tutto OK mette la stringa di risposta nella variabile Reply
  215.   Reply = strdata
  216.   getreply = 0
  217.  Else
  218. 'dopo 5 secondi esce con errore
  219.   Reply = ""
  220.   getreply = -1
  221.  End If
  222. End Function
  223.  
  224. Function MailTo(ByVal MailServer As String, ByVal Subject As String, ByVal senderName As String, ByVal senderEmail As String, ByVal RecipientEmail As String, ByVal msgfile As String, ByVal logoFile As String) As Integer
  225. 'esegue la spedizione del messaggio
  226. 'richiede il nome del server, il file che contiene il messaggio,
  227. 'il subject del messaggio, il nome e la email di chi invia,
  228. 'la e-mail a cui il messaggio va inviato
  229. WS(1).Protocol = sckTCPProtocol 'inizializza WINSOCK con protocollo TCP
  230. WS(1).Connect MailServer, 25 '(porta di default dei servizi SMTP)
  231. Reply$ = ""
  232. 'attende connessione col server: eccezionalmente si lascia piu' tempo (8 secondi)
  233. t# = Timer
  234.  
  235.  While Timer < t# + 8 And WS(1).State <> sckConnected
  236.   DoEvents
  237.  Wend
  238.  If WS(1).State <> sckConnected Then
  239.   WS(1).Close
  240.   MsgBox "Remote Host Timeout"
  241.   MailTo = -1
  242.   Exit Function
  243.  End If
  244. t# = Timer
  245.  While Timer < t# + 5 And InStr(strdata, Chr$(13) & Chr$(10)) = 0
  246.   DoEvents
  247.  Wend
  248. aa% = getreply(Reply$)
  249. If aa% Then
  250.  WS(1).Close
  251.  MailTo = -1
  252.  Exit Function
  253. End If
  254. strdata = ""
  255. 'il programma si 'presenta' al server inviando il proprio IP address
  256. WS(1).SendData "HELO " & WS(1).LocalIP & Chr$(13) & Chr$(10)
  257. aa% = getreply(Reply$)
  258. If aa% Then
  259.  WS(1).Close
  260.  MailTo = -1
  261.  Exit Function
  262. End If
  263. strdata = ""
  264. 'specifica l'indirizzo da cui proviene la mail
  265. WS(1).SendData "MAIL FROM:<" & senderEmail & ">" & Chr$(13) & Chr$(10)
  266. Reply$ = ""
  267. aa% = getreply(Reply$)
  268. If aa% Then
  269.  WS(1).Close
  270.  MailTo = -1
  271.  Exit Function
  272. End If
  273. strdata = ""
  274. 'specifica l'indirizzo a cui inviare la mail
  275. WS(1).SendData "RCPT TO:<" & RecipientEmail & ">" & Chr$(13) & Chr$(10)
  276. aa% = getreply(Reply$)
  277. If aa% Then
  278.  WS(1).Close
  279.  MailTo = -1
  280.  Exit Function
  281. End If
  282. strdata = ""
  283.  
  284. 'specifica i dati essenziali della mail
  285.  
  286. OKToSend = False
  287. WS(1).SendData "DATA" & Chr$(13) & Chr$(10)
  288. 'attende l'avvenuta consegna pacchetto
  289. While OKToSend = False: DoEvents: Wend
  290.  
  291. OKToSend = False
  292. WS(1).SendData "From: " & senderName & " <" & senderEmail & ">" & Chr$(13) & Chr$(10)
  293. While OKToSend = False: DoEvents: Wend
  294.  
  295. OKToSend = False
  296. WS(1).SendData "To: <" & RecipientEmail & "> " & Chr$(13) & Chr$(10)
  297. While OKToSend = False: DoEvents: Wend
  298.  
  299. OKToSend = False
  300. WS(1).SendData "Subject: " & Subject & Chr$(13) & Chr$(10)
  301. While OKToSend = False: DoEvents: Wend
  302.  
  303. OKToSend = False
  304. WS(1).SendData vbCrLf
  305. While OKToSend = False: DoEvents: Wend
  306.  
  307. strdata = ""
  308. 'Open msgfile For Input As 10
  309. 'While EOF(10) = False
  310. ' Line Input #10, l$
  311.  ' elimina eventuali linee composte solo da un punto (vedi piu' avanti)
  312. ' If l$ = "." Then l$ = "_"
  313.  
  314.  OKToSend = False
  315.  WS(1).SendData msgfile & Chr$(13) & Chr$(10)
  316.  While OKToSend = False: DoEvents: Wend
  317.  
  318. ' Wend
  319. 'Close 10
  320.  
  321. 'invia il logo, se esiste
  322. If logoFile <> "" Then
  323.  'crea un file temporaneo per la successiva divisione, linea per linea
  324.  UU$ = ""
  325.  uuEncodeToFile "x.uue", logoFile
  326.  
  327.  Open "x.uue" For Input As 10
  328.  While EOF(10) = False
  329.   Line Input #10, l$
  330.    
  331.    OKToSend = False
  332.    WS(1).SendData l$ & Chr$(13) & Chr$(10)
  333.    While OKToSend = False: DoEvents: Wend
  334.  
  335. Wend
  336. Close 10
  337. End If
  338.  
  339. 'invia il messaggio, con alla fine una linea composta solo da un "."
  340. WS(1).SendData Chr$(13) & Chr$(10) & "." & Chr$(13) & Chr$(10)
  341. aa% = getreply(Reply$)
  342. If aa% Then
  343.  WS(1).Close
  344.  MailTo = -1
  345.  Exit Function
  346. End If
  347. strdata = ""
  348. WS(1).SendData "QUIT" & Str$(i) & Chr$(13) & Chr$(10)
  349. aa% = getreply(Reply$)
  350. WS(1).Close
  351. MailTo = 0
  352. End Function
  353.  
  354. Private Sub WS_SendComplete(Index As Integer)
  355. 'setta il flag di avvenuta consegna pacchetto
  356. OKToSend = True
  357. End Sub
  358.  
  359. Sub deletetemp()
  360. If TxtLogo.Text <> "" Then
  361. Dim dirp As String, dir1 As String, dir2 As String, dir3 As Long, dir4 As Long, dir5 As Long, dirf As String, filetemp As String
  362. dirp = TxtLogo.Text
  363. dir1 = Right$(dirp, pos)
  364. dir2 = Left$(dir1, 1)
  365. If dir2 = "\" Then
  366. dir3 = Len(dir1) - 1
  367. dir4 = Len(dirp)
  368. dir5 = dir4 - dir3
  369. dirf = Left$(dirp, dir5)
  370. filetemp = dirf & "x.uue"
  371. If Dir(filetemp) <> "" Then
  372. Kill filetemp
  373. End If
  374. Else
  375. pos = pos + 1
  376. Call deletetemp
  377. End If
  378. End If
  379. End Sub