如何通过VB在本地主机上发送邮件smtp

时间:2017-01-01 18:06:34

标签: asp.net vb.net email

我已经将VB.net用于我的项目,票务系统,在那里您添加新票据,它应该将邮件发送到我在其他类中定义的一些电子邮件

但我有愚蠢的问题,即通过本地主机发送邮件。

是否有任何来自此源代码的建议,当我上传到特定域时它可以工作,但是对于localhost不与我合作,当我运行我的项目时,我没有收到任何邮件

我想从localhost发送邮件

Private Function SendConfirmationEmail(ByVal EmailAddress As String, ByVal Operation As String, ByVal CorreCode As String, ByVal CorrSubj As String, ByVal CutName As String, ByVal phone As String, ByVal CustomerEmail As String) As Boolean
    ''''''''''''''''''''''Getting Email Setting Information'''''''''''''''''''''''''''''''''''''''
    Try
        Dim FromMail As String = System.Configuration.ConfigurationManager.AppSettings.GetValues("DefualtMail")(0).ToString()
        Dim PassMail As String = System.Configuration.ConfigurationManager.AppSettings.GetValues("DefualtMailPass")(0).ToString
        Dim SenderName As String = "Customer Managment Team"
        Dim SMTPHost As String = System.Configuration.ConfigurationManager.AppSettings.GetValues("SMTPHost")(0).ToString
        ''''''''''''''''''''''''''''''''''''Sending Emails'''''''''''''''''''''''''''''''''''''''''''''''''
        Dim Mail As New MailMessage
        Dim Body As String = ""
        Dim Subject As String = Operation
        Dim SendTo As String = EmailAddress
        ''''''''''''''''''''''''''''''''''E-mail'''''''''''''''''''''''''''''''''''''    
        If SendTo <> vbNullString Then
            Mail.To.Clear()
            Mail.CC.Clear()
            Mail.Bcc.Clear()
            Mail.To.Add(SendTo)
            Mail.From = New MailAddress(FromMail, "Ticket Code   : " + CorreCode)
            Mail.IsBodyHtml = True
            Dim reader As StreamReader
            reader = New StreamReader(Server.MapPath("Index.html"))
            Body = reader.ReadToEnd
            Body = Body.Replace("MessageSubject", Operation)
            Body = Body.Replace("Description", "description  :  " + CorrSubj)
            Body = Body.Replace("customer_info", "Customer Name  :  " + CutName)
            Body = Body.Replace("phone_number", "Customer Phone  :  " + phone)
            Body = Body.Replace("email_address", "Customer address  :  " + CustomerEmail)
            ' Body = Body.Replace("PropertyTitle", "Ticket Code   :" + CorreCode + "   Ticket Description  :" + CorrSubj + " Customer info : " + CutName + " phone number : " + phone + " email_address : " + EmailAddress)
            Mail.Body = Body
            ' "<html dir='ltr'><body><h1>Confirmation</h1><br/> Please confirm you email at this link <br/> <a href='108.60.209.97/enmaa/ConfirmEmail.aspx/Enmaa0000" + ApproveId + "'>Confirm</a></body></html>"
            Mail.Subject = Subject
            '######################################## Sending The EMail########################################################
            Dim SMTP As New SmtpClient(SMTPHost)
            SMTP.Credentials = New System.Net.NetworkCredential(FromMail, PassMail)
            SMTP.Host = SMTPHost
            SMTP.Port = 587 '587
            SMTP.EnableSsl = True
            SMTP.Send(Mail)
        End If
        Return True

0 个答案:

没有答案