Skip to main content

AccessTr.neT


Ünvana Göre Mail Gönderimi

Ünvana Göre Mail Gönderimi

Çözüldü #2
Sn. bonasera,

Yorumunuzda seçili kişiye mail gönderebiliyorum yazmışsınız ama gönderdiğiniz örnekteki formda E-Posta komut düğmesinde herhangi bir kod görünmüyor.

Ayrıca bahsettiğiniz gibi Ünvan seçme içeren bir formda yok.

Benim daha önce DAO ile sorgudaki kayıtları teker teker okuyup sırayla mail gönderdiğim bir kod vardı, onu gönderiyorum

Private Sub Ilgililere_Mail_Gonder()
On Error GoTo Hata
'---------------------------------------------------------------
Dim DB As DAO.Database, RS As DAO.Recordset
Dim objMessage As Object
Dim SMTP_Sunucu, strBody
Dim Kullanicinin_Adi, Kullanicinin_Mail_Adresi, Kullanicinin_Mail_Sifresi
Dim TalepEdenin_Adi, TalepEdenin_Mail_Adresi
Dim Onceki_TALEP_EDEN
Const cdoAnonymous = 0
Const cdoBasic = 1
Const cdoNTLM = 2
'---------------------------------------------------------------
SMTP_Sunucu = "smtp.bline.net.tr"
Kullanicinin_Adi = Me.TALEP_EDEN.Column(1)
Kullanicinin_Mail_Adresi = Me.TALEP_EDEN.Column(2)
Kullanicinin_Mail_Sifresi = Me.TALEP_EDEN.Column(3)
If Kullanicinin_Mail_Adresi = "" Or Kullanicinin_Mail_Sifresi = "" Then
MsgBox "Gerekli bilgileriniz eksik olduğu için Malzeme Talep Edenlere e-posta gönderilemiyor !" & vbCrLf & "Lütfen Bilgi Teknolojileri Departmanına bilgi veriniz", vbCritical, "Hata oluştu."
Exit Sub
End If
'---------------------------------------------------------------
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("Select * From Malzeme_Alis_MailListesi Where HRB_ID=" & [Forms]![Malzeme_Alis]![IrsListesi], dbOpenForwardOnly)
Set objMessage = CreateObject("CDO.Message")
Onceki_TALEP_EDEN = ""
Do While Not RS.EOF
'---------------------------------------------------------------
If Onceki_TALEP_EDEN <> RS.Fields("TALEP_EDEN") Then
'---------------------------------------
'Bir önceki kişiye mail gönderiliyor
'---------------------------------------
If Onceki_TALEP_EDEN <> "" Then
strBody = strBody & "</table>"
strBody = strBody & "</font><br><br>"
'---------------------------------------------------------------
objMessage.Subject = "Gelen Malzeme Bilgisi"
objMessage.From = Kullanicinin_Adi & "<" & Kullanicinin_Mail_Adresi & ">"
objMessage.To = TalepEdenin_Mail_Adresi
objMessage.HTMLBody = strBody
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = Kullanicinin_Mail_Adresi
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Kullanicinin_Mail_Sifresi
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTP_Sunucu
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
objMessage.Send
'---------------------------------------------------------------
End If
TalepEdenin_Adi = RS.Fields("Kull_ADI")
TalepEdenin_Mail_Adresi = RS.Fields("Kull_MAIL")
'---------------------------------------
' Yeni kişi için yeni mail oluşturuluyor
'---------------------------------------
strBody = ""
strBody = strBody & "<p>"
strBody = strBody & "<font face='Verdana' size='2'>"
strBody = strBody & "Sn. " & TalepEdenin_Adi
strBody = strBody & "<br><br>"
strBody = strBody & "Talep etmiş olduğunuz malzeme(ler) gelmiştir."
strBody = strBody & "<br><br>"
strBody = strBody & "'MALZEME TALEPLERİ' programında açılış formunda veya "
strBody = strBody & "<br>"
strBody = strBody & " menüden 'Teslim Onayı' formunu seçerek gelen malzemeleri "
strBody = strBody & "<br>"
strBody = strBody & " teslim aldığınızı onaylamalısınız."
strBody = strBody & "<br>"
strBody = strBody & "Teslim onayından sonra malzemelerinizi depodan alabilirsiniz."
strBody = strBody & "<br><br><br>"
strBody = strBody & "Gelen Malzemeler:"
strBody = strBody & "</font>"
strBody = strBody & "</p>"
strBody = strBody & "<table border='1' cellspacing='0' cellpadding='1' font face='Verdana' size='1' bgcolor='LightBlue'>"
strBody = strBody & "<tr>"
strBody = strBody & "<td><b>&nbsp;Talep Tarihi&nbsp;</b></td>"
strBody = strBody & "<td><b>&nbsp;Talep No&nbsp;</b></td>"
strBody = strBody & "<td><b>&nbsp;Malzeme&nbsp;</b></td>"
strBody = strBody & "<td><b>&nbsp;Miktar&nbsp;</b></td>"
strBody = strBody & "</tr>"
'------
Onceki_TALEP_EDEN = RS.Fields("TALEP_EDEN")
End If
'---------------------------------------------------------------
strBody = strBody & "<tr>"
strBody = strBody & "<td>&nbsp;" & RS.Fields("TALEP_TARIHI") & "&nbsp;</td>"
strBody = strBody & "<td>&nbsp;" & RS.Fields("TALEP_NO") & "&nbsp;</td>"
If IsNull(RS.Fields("MLZ_OZELLIK")) Then
strBody = strBody & "<td>&nbsp;" & RS.Fields("MLZ_TANIMI") & "&nbsp;</td>"
Else
strBody = strBody & "<td>&nbsp;" & RS.Fields("MLZ_TANIMI") & "(" & RS.Fields("MLZ_OZELLIK") & ")&nbsp;</td>"
End If
strBody = strBody & "<td align=right>&nbsp;" & RS.Fields("MLZ_MIKTARI") & " " & RS.Fields("MLZ_BIRIMI") & "&nbsp;</td>"
strBody = strBody & "</tr>"
RS.MoveNext
Loop
RS.Close
Set RS = Nothing

'---------------------------------------
'Son kişiye mail gönderiliyor
'---------------------------------------
If Onceki_TALEP_EDEN <> "" Then
strBody = strBody & "</table>"
strBody = strBody & "</font><br><br>"
'---------------------------------------------------------------
objMessage.Subject = "Gelen Malzeme Bilgisi"
objMessage.From = Kullanicinin_Adi & "<" & Kullanicinin_Mail_Adresi & ">"
objMessage.To = TalepEdenin_Mail_Adresi
objMessage.HTMLBody = strBody
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = Kullanicinin_Mail_Adresi
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Kullanicinin_Mail_Sifresi
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTP_Sunucu
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
objMessage.Send
'---------------------------------------------------------------
End If

MsgBox "İlgili kişi(lere) e-posta gönderilmiştir.", vbInformation, "İşlem tamam"
Exit Sub
'---------------------------------------------------------------
Hata:
MsgBox "Talep edene e-posta gönderimi başarısız oldu!", vbCritical, "Hata oluştu."
End Sub
Bu kodda aynı kişinin birden fazla olabilmesi durumunda bir kez gönderebilmesi için bazı kontroller var (Onceki_TALEP_EDEN),
onları kaldırmanız lazım. O zaman DAO kullanmışım, isterseniz ADO'ya çevirin, daha iyi ve hızlı olur.

Ayrıca, bu kodun gönderdiği mailin örnek formatını ve benzer programını aşağıdaki konunun 3. ve 5. sayfalarında bulabilirsiniz.
formdaki bilgileri ilgili kişiye eposta olarak gönderme

Örneğimde kullandığım metodu sn. ozanakkaya'nın aşağıdaki örneğinden alınmıştır.
SMTP Hesabıyla E-mail Gönderme Uygulaması
Bildiğini bilenin arkasından git, bildiğini bilmeyeni uyar, bilmediğini bilene öğret, bilmediğini bilmeyenden kaç.
Konfüçyüs
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
Ünvana Göre Mail Gönderimi - Yazar: bonasera - 26/07/2012, 10:22
Cvp: Ünvana Göre Mail Gönderimi - Yazar: Seruz - 27/07/2012, 04:12
Cvp: Ünvana Göre Mail Gönderimi - Yazar: bonasera - 27/07/2012, 09:40
Cvp: Ünvana Göre Mail Gönderimi - Yazar: Seruz - 28/07/2012, 02:24
Cvp: Ünvana Göre Mail Gönderimi - Yazar: bonasera - 28/07/2012, 09:43
Cvp: Ünvana Göre Mail Gönderimi - Yazar: Seruz - 28/07/2012, 23:35
Cvp: Ünvana Göre Mail Gönderimi - Yazar: bonasera - 29/07/2012, 02:16
Cvp: Ünvana Göre Mail Gönderimi - Yazar: Seruz - 29/07/2012, 14:22
Cvp: Ünvana Göre Mail Gönderimi - Yazar: Seruz - 29/07/2012, 14:30
Cvp: Ünvana Göre Mail Gönderimi - Yazar: bonasera - 29/07/2012, 18:31
Cvp: Ünvana Göre Mail Gönderimi - Yazar: bonasera - 01/08/2012, 17:46
Cvp: Ünvana Göre Mail Gönderimi - Yazar: bonasera - 06/08/2012, 13:19
Cvp: Ünvana Göre Mail Gönderimi - Yazar: simendifer - 08/08/2012, 20:31
Cvp: Ünvana Göre Mail Gönderimi - Yazar: bonasera - 08/08/2012, 22:47
Cvp: Ünvana Göre Mail Gönderimi - Yazar: bonasera - 08/08/2012, 22:54
Cvp: Ünvana Göre Mail Gönderimi - Yazar: simendifer - 08/08/2012, 23:33
Cvp: Ünvana Göre Mail Gönderimi - Yazar: bonasera - 09/08/2012, 09:08
Task