Selam arkadaşlar hepinizin bildigi gibi visual basic 6 ile görsel programlama gelişti .
vb6 programlama dilleri arasında bende varım diyebildi. her alanda kolaylık saglayan bi programlama dili oldugu için bilen kişi çok iyi işler yapablir.
Programın yazıldıgı dil degil yazılış tarzı önemli oldu (benim fikrim )
Visual basic6 da çogu kişi windows7 de mail yollattıramaz. sebebine gelince windows7 de uac vs oldugu için mail attırmak nerdeyse zordur. bu yüzden çogu kişi vb.net e geçti ama vb6 da da mail atmak mümkün
şimdi kodlara gelelim.
Verdigim kodları Projenize Add - class - class modl ekleyerek içine şu kodları yazın..
Private Declare Function GetFileAttributesW Lib "KERNEL32" (ByVal lpFileName As Long) As Long
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Private Const MICROSOFT_CDO_CONFIGURATION$ = "http://schemas.microsoft.com/cdo/configuration/"
Private lngPort&
Private strUser$
Private strPass$
Private strFrom$
Private strServer$
Private strSubject$
Private strMessage$
Private strDestinatary$
Private strAttachedFile$
Private objCDO As Object
Private bolUseAuntentificacion As Boolean
Private bolSSL As Boolean
'~~~~~~~~~~~~~~~~~~~> Properties
Friend Property Let Server(ByRef Value$): strServer = Value: End Property
Friend Property Let Destinatary(ByRef Value$): strDestinatary = Value: End Property
Friend Property Let From(ByRef Value$): strFrom = Value: End Property
Friend Property Let Subject(ByRef Value$): strSubject = Value: End Property
Friend Property Let Message(ByRef Value$): strMessage = Value: End Property
Friend Property Let AttachedFile(ByRef Value$): strAttachedFile = Value: End Property
Friend Property Let Port(ByVal Value&): lngPort = Value: End Property
Friend Property Let User(ByRef Value$): strUser = Value: End Property
Friend Property Let Password(ByRef Value$): strPass = Value: End Property
Friend Property Let UseAuntentificacion(ByVal Value As Boolean): bolUseAuntentificacion = Value: End Property
Friend Property Let SSL(ByVal Value As Boolean): bolSSL = Value: End Property
'~~~~~~~~~~~~~~~~~~~> fonksiyon
Friend Function SendMail() As Boolean
If InternetGetConnectedState(&H0&, &H0&) Then
If LenB(strPass) = 0 Then Exit Function
If LenB(strUser) = 0 Then Exit Function
If LenB(strFrom) = 0 Then Exit Function
If LenB(strServer) = 0 Then Exit Function
If LenB(strDestinatary) = 0 Then Exit Function
If lngPort < 0 Or lngPort > &HFDE8& Then Exit Function
On Error GoTo FatalError
With objCDO
With .Configuration
.Fields(MICROSOFT_CDO_CONFIGURATION & "smtpserver") = strServer
.Fields(MICROSOFT_CDO_CONFIGURATION & "sendusing") = &H2&
With .Fields
.Item(MICROSOFT_CDO_CONFIGURATION & "smtpserverport") = lngPort
.Item(MICROSOFT_CDO_CONFIGURATION & "smtpauthenticate") = Abs(bolUseAuntentificacion)
.Item(MICROSOFT_CDO_CONFIGURATION & "smtpconnectiontimeout") = &HA&
If bolUseAuntentificacion Then
.Item(MICROSOFT_CDO_CONFIGURATION & "sendusername") = strUser
.Item(MICROSOFT_CDO_CONFIGURATION & "sendpassword") = strPass
.Item(MICROSOFT_CDO_CONFIGURATION & "smtpusessl") = bolSSL
End If
End With
End With
.To = strDestinatary
.From = strFrom
.Subject = strSubject
.TextBody = strMessage ' mesaj tipi text siz bunu html yapablirsiniz
If LenB(strAttachedFile) Then
'// GetFileAttributesW is the fastest way to check if a file exists.
If GetFileAttributesW(StrPtr(strAttachedFile)) > -1 Then
.AddAttachment (strAttachedFile)
End If
End If
.Configuration.Fields.Update
.Send
End With
SendMail = True
End If
FatalError:
End Function
Private Sub Class_Initialize()
Set objCDO = CreateObject("CDO.Message")
End Sub
Private Sub Class_Terminate()
Set objCDO = Nothing
End Sub
Class modulümüzü ekledik. şimdi geldik form a yazılacak kodmuza
Bir buton ekleyin.
command1 oldugunu varsayalım .
command1 in click olayına şunu yazın
Dim c As New class1
With c
.Server = "smtp.gmail.com" ' gmaile mail yollamak için smtp adresi
.Port = 465 ' 465 inci portdan yollucak
.UseAuntentificacion = True ' dogru
.SSL = True ' dogru
.User = "mail adresiniz" ' isterseniz text1.text yazarak mail adresinizi oradan yazablirsiniz
.Password = "mailşifreniz" ' bunu da text2.text yazablirsinz TABİKİ TEXT KUTULARINI EKLEMEYİ UNUTMAYIN
.Subject = "Harmmy Mail Test" 'Mailin konu başlıgı
.From = "Kimden geldigi dair yazı"
.Destinatary = "Alici mail adres" ' isterseniz bir text daha ekleyerek text3.text yapablirsiniz
.Message = "Harmmy mail gönderme test onaylandı" ' mail içindeki yazı
If .SendMail Then MsgBox "Mail Gönderildi.!"
End With
Set c = Nothing
Evet bu kadar
umrım yararlanırsınız
vb6 programlama dilleri arasında bende varım diyebildi. her alanda kolaylık saglayan bi programlama dili oldugu için bilen kişi çok iyi işler yapablir.
Programın yazıldıgı dil degil yazılış tarzı önemli oldu (benim fikrim )
Visual basic6 da çogu kişi windows7 de mail yollattıramaz. sebebine gelince windows7 de uac vs oldugu için mail attırmak nerdeyse zordur. bu yüzden çogu kişi vb.net e geçti ama vb6 da da mail atmak mümkün
şimdi kodlara gelelim.
Verdigim kodları Projenize Add - class - class modl ekleyerek içine şu kodları yazın..
Private Declare Function GetFileAttributesW Lib "KERNEL32" (ByVal lpFileName As Long) As Long
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Private Const MICROSOFT_CDO_CONFIGURATION$ = "http://schemas.microsoft.com/cdo/configuration/"
Private lngPort&
Private strUser$
Private strPass$
Private strFrom$
Private strServer$
Private strSubject$
Private strMessage$
Private strDestinatary$
Private strAttachedFile$
Private objCDO As Object
Private bolUseAuntentificacion As Boolean
Private bolSSL As Boolean
'~~~~~~~~~~~~~~~~~~~> Properties
Friend Property Let Server(ByRef Value$): strServer = Value: End Property
Friend Property Let Destinatary(ByRef Value$): strDestinatary = Value: End Property
Friend Property Let From(ByRef Value$): strFrom = Value: End Property
Friend Property Let Subject(ByRef Value$): strSubject = Value: End Property
Friend Property Let Message(ByRef Value$): strMessage = Value: End Property
Friend Property Let AttachedFile(ByRef Value$): strAttachedFile = Value: End Property
Friend Property Let Port(ByVal Value&): lngPort = Value: End Property
Friend Property Let User(ByRef Value$): strUser = Value: End Property
Friend Property Let Password(ByRef Value$): strPass = Value: End Property
Friend Property Let UseAuntentificacion(ByVal Value As Boolean): bolUseAuntentificacion = Value: End Property
Friend Property Let SSL(ByVal Value As Boolean): bolSSL = Value: End Property
'~~~~~~~~~~~~~~~~~~~> fonksiyon
Friend Function SendMail() As Boolean
If InternetGetConnectedState(&H0&, &H0&) Then
If LenB(strPass) = 0 Then Exit Function
If LenB(strUser) = 0 Then Exit Function
If LenB(strFrom) = 0 Then Exit Function
If LenB(strServer) = 0 Then Exit Function
If LenB(strDestinatary) = 0 Then Exit Function
If lngPort < 0 Or lngPort > &HFDE8& Then Exit Function
On Error GoTo FatalError
With objCDO
With .Configuration
.Fields(MICROSOFT_CDO_CONFIGURATION & "smtpserver") = strServer
.Fields(MICROSOFT_CDO_CONFIGURATION & "sendusing") = &H2&
With .Fields
.Item(MICROSOFT_CDO_CONFIGURATION & "smtpserverport") = lngPort
.Item(MICROSOFT_CDO_CONFIGURATION & "smtpauthenticate") = Abs(bolUseAuntentificacion)
.Item(MICROSOFT_CDO_CONFIGURATION & "smtpconnectiontimeout") = &HA&
If bolUseAuntentificacion Then
.Item(MICROSOFT_CDO_CONFIGURATION & "sendusername") = strUser
.Item(MICROSOFT_CDO_CONFIGURATION & "sendpassword") = strPass
.Item(MICROSOFT_CDO_CONFIGURATION & "smtpusessl") = bolSSL
End If
End With
End With
.To = strDestinatary
.From = strFrom
.Subject = strSubject
.TextBody = strMessage ' mesaj tipi text siz bunu html yapablirsiniz
If LenB(strAttachedFile) Then
'// GetFileAttributesW is the fastest way to check if a file exists.
If GetFileAttributesW(StrPtr(strAttachedFile)) > -1 Then
.AddAttachment (strAttachedFile)
End If
End If
.Configuration.Fields.Update
.Send
End With
SendMail = True
End If
FatalError:
End Function
Private Sub Class_Initialize()
Set objCDO = CreateObject("CDO.Message")
End Sub
Private Sub Class_Terminate()
Set objCDO = Nothing
End Sub
Class modulümüzü ekledik. şimdi geldik form a yazılacak kodmuza
Bir buton ekleyin.
command1 oldugunu varsayalım .
command1 in click olayına şunu yazın
Dim c As New class1
With c
.Server = "smtp.gmail.com" ' gmaile mail yollamak için smtp adresi
.Port = 465 ' 465 inci portdan yollucak
.UseAuntentificacion = True ' dogru
.SSL = True ' dogru
.User = "mail adresiniz" ' isterseniz text1.text yazarak mail adresinizi oradan yazablirsiniz
.Password = "mailşifreniz" ' bunu da text2.text yazablirsinz TABİKİ TEXT KUTULARINI EKLEMEYİ UNUTMAYIN
.Subject = "Harmmy Mail Test" 'Mailin konu başlıgı
.From = "Kimden geldigi dair yazı"
.Destinatary = "Alici mail adres" ' isterseniz bir text daha ekleyerek text3.text yapablirsiniz
.Message = "Harmmy mail gönderme test onaylandı" ' mail içindeki yazı
If .SendMail Then MsgBox "Mail Gönderildi.!"
End With
Set c = Nothing
Evet bu kadar


