Skip to main content

AccessTr.neT


Microsoft Visual Studio 2008 de Mail Gönderme

Microsoft Visual Studio 2008 de Mail Gönderme

Çözüldü #10
Option Explicit 
Private Response As String

Sub SendEmail(ServerDomain As String, FromEmail As String, ToEmail As String, Subject As String, Body As String )

w.LocalPort = 0

If w.State <> sckClosed Then w.Close

w.Protocol = sckTCPProtocol
w.RemoteHost = ServerDomain
w.RemotePort = 25
w.Connect

WaitForResponse ("220" )

w.SendData "HELO " & ServerDomain & vbCrLf
WaitForResponse ("250" )

w.SendData "MAIL FROM: <" & FromEmail & ">" & vbCrLf
WaitForResponse ("250" ) 'wait for response

w.SendData "RCPT TO: <" & ToEmail & ">" & vbCrLf
WaitForResponse ("250" ) 'wait for response

w.SendData ("data" & vbCrLf )

WaitForResponse ("354" )
w.SendData "From: " & FromEmail & vbCrLf
w.SendData "X-Mailer: BASTON SMTP Mailer" & vbCrLf
w.SendData "To: " & ToEmail & vbCrLf
w.SendData "Subject: " & Subject & vbCrLf

w.SendData Body & vbCrLf

w.SendData "." & vbCrLf
WaitForResponse ("250" )

w.SendData "quit" & vbCrLf
WaitForResponse ("221" )

w.Close
MsgBox "Mesajınız başarıyla gönderildi.", vbExclamation, "Mesajını Gönderildi."
End Sub
Sub WaitForResponse(ResponseCode As String )
Dim Reply As Integer
Dim Start As Single
Dim Tmr As Single
Start = Timer
While Len(Response ) = 0
Tmr = Start - Timer
DoEvents
If Tmr > 10 Then
MsgBox "Hata:" + vbCrLf + "İşlem zamanaşımına uğradı!", vbExclamation, "İşlem Başarısız"
Exit Sub
End If
Wend
While Left(Response, 3 ) <> ResponseCode
DoEvents
If Tmr > 10 Then
MsgBox "Hata:" + vbCrLf + "Geçersiz bir yanıt alındı: " + Response + vbCrLf + "Expected code: " + ResponseCode, vbExclamation, "İşlem Başarısız."
Exit Sub
End If
Wend
Response = ""
End Sub
Private Sub cmdExit_Click( )
Unload Me
End
End Sub
Private Sub cmdSend_Click( )
SendEmail txtServerDomain, txtFromEmail, txtToEmail, txtSubject, txtMessage
End Sub
Private Sub w_DataArrival(ByVal bytesTotal As Long )
w.GetData Response
End Sub


'// Programın başına aşağıdaki satırı ekleyerek System.Net namespace'i ekleyin 
Imports System.Net.Mail

'// Programınıza bir buton ekleyerek onClick olayına aşağıdaki kodları yapıştırın
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs ) Handles Button1.Click

Dim strGonderen As New MailAddress("[email protected]", "Gönderici Adı" )
Dim strAlici As New MailAddress("[email protected]", "Alıcı Adı" )
Dim mailMsg As New MailMessage(strGonderen, strAlici )

With mailMsg
.Subject = "Konu"
.Body = "E-posta metni"
.IsBodyHtml = True '// Mesaj Html mi, değil mi? True veya False
End With

Try
Dim client As New SmtpClient("smtp.site.com" )
client.Send(mailMsg )
Catch
End Try

MsgBox("E-Posta gönderildi.", MsgBoxStyle.Information, "E-Posta Gönder" )

End Sub
.



Birde bu kodları denermisin
Son Düzenleme: 19/05/2011, 11:13, Düzenleyen: DUAYEN.
Cevapla

Bir hesap oluşturun veya yorum yapmak için giriş yapın

Yorum yapmak için üye olmanız gerekiyor

ya da

Bu Konudaki Yorumlar
Cvp: Microsoft Visual Studio 2008 de Mail Gönderme - Yazar: DUAYEN - 19/05/2011, 11:10
Task