hastiam
سه شنبه 14 اردیبهشت 1389, 12:41 عصر
سلام
من می خوام برنامه ی (Webای) بنویسم که کاربر وقتی در TextBox ایمیل را وارد می کنه و دکمه تایید رو می زنه یک ایمیل به آن ایمیل وارد شده در Textbox فرستاده بشه. من از تنظیمات SMTP استفاده کردم و کد ارسال ایمیل رو هم نوشتم اما نمی دونم چرا ایمیلی فرستاده نمی شه.
یک کلاس به شکل زیر تعریف کردم:
Public Class MailHelper
Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, ByVal subject As String, ByVal body As String)
Dim mMailMessage As New MailMessage
mMailMessage.From = New MailAddress(from)
mMailMessage.To.Add(New MailAddress(recepient))
If Not bcc Is Nothing And bcc <> String.Empty Then
mMailMessage.Bcc.Add(New MailAddress(bcc))
End If
If Not cc Is Nothing And cc <> String.Empty Then
mMailMessage.CC.Add(New MailAddress(cc))
End If
mMailMessage.Subject = subject
mMailMessage.Body = body
mMailMessage.IsBodyHtml = True
mMailMessage.Priority = MailPriority.Normal
Dim mSmptClient As New SmtpClient()
mSmptClient.Send(mMailMessage)
End Sub
Public Shared Function SendActivationLink(ByVal ReceiverEmail As String, ByVal UniqueID As Guid) As Boolean
Dim FilePath As String = System.Web.Hosting.HostingEnvironment.MapPath("~/Emails/ActivationLink.htm")
Dim Sr As New System.IO.StreamReader(FilePath)
Dim body As String = Sr.ReadToEnd()
Sr.Close()
Try
Dim Email As String = "<" & ReceiverEmail & ">"
SendMailMessage("taha@gmail.com", Email, "", "", "ActivationLink", body)
Return True
Catch ex As Exception
Return False
End Try
End Function
End Class
تو web.config دستورات زیر را نوشتم:
<system.net >
<mailSettings >
<smtp from ="Taha@gmail.com">
<network host ="smtp.gmail.com" port ="995" userName ="" password =""/>
</smtp>
</mailSettings>
</system.net>
در پشت دکمه تایید دستور زیر رو نوشتم:
If MailHelper.SendActivationLink(Txt_Email.Text, UniqueID) = True Then
Lbl_Message.Text = "OK"
Else
Lbl_Message.Text = "Error"
End If
من می خوام برنامه ی (Webای) بنویسم که کاربر وقتی در TextBox ایمیل را وارد می کنه و دکمه تایید رو می زنه یک ایمیل به آن ایمیل وارد شده در Textbox فرستاده بشه. من از تنظیمات SMTP استفاده کردم و کد ارسال ایمیل رو هم نوشتم اما نمی دونم چرا ایمیلی فرستاده نمی شه.
یک کلاس به شکل زیر تعریف کردم:
Public Class MailHelper
Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, ByVal subject As String, ByVal body As String)
Dim mMailMessage As New MailMessage
mMailMessage.From = New MailAddress(from)
mMailMessage.To.Add(New MailAddress(recepient))
If Not bcc Is Nothing And bcc <> String.Empty Then
mMailMessage.Bcc.Add(New MailAddress(bcc))
End If
If Not cc Is Nothing And cc <> String.Empty Then
mMailMessage.CC.Add(New MailAddress(cc))
End If
mMailMessage.Subject = subject
mMailMessage.Body = body
mMailMessage.IsBodyHtml = True
mMailMessage.Priority = MailPriority.Normal
Dim mSmptClient As New SmtpClient()
mSmptClient.Send(mMailMessage)
End Sub
Public Shared Function SendActivationLink(ByVal ReceiverEmail As String, ByVal UniqueID As Guid) As Boolean
Dim FilePath As String = System.Web.Hosting.HostingEnvironment.MapPath("~/Emails/ActivationLink.htm")
Dim Sr As New System.IO.StreamReader(FilePath)
Dim body As String = Sr.ReadToEnd()
Sr.Close()
Try
Dim Email As String = "<" & ReceiverEmail & ">"
SendMailMessage("taha@gmail.com", Email, "", "", "ActivationLink", body)
Return True
Catch ex As Exception
Return False
End Try
End Function
End Class
تو web.config دستورات زیر را نوشتم:
<system.net >
<mailSettings >
<smtp from ="Taha@gmail.com">
<network host ="smtp.gmail.com" port ="995" userName ="" password =""/>
</smtp>
</mailSettings>
</system.net>
در پشت دکمه تایید دستور زیر رو نوشتم:
If MailHelper.SendActivationLink(Txt_Email.Text, UniqueID) = True Then
Lbl_Message.Text = "OK"
Else
Lbl_Message.Text = "Error"
End If