Vb.net Windows服务背后的isa服务器 [英] Vb.net Windows Services behind isa server

查看:58
本文介绍了Vb.net Windows服务背后的isa服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们感谢您的时间和帮助..



i在vb.net中有一个Windows服务,可以使用任何主机发送电子邮件

像yahoo,gmail,内部交换。



i有一个问题我的电脑在网络中使用isa服务器作为代理



当我尝试从Windows服务发送电子邮件时我得到了

无法连接到远程主机



但是,如果我在Windows窗体中测试发送电子邮件的功能,我可以发送电子邮件



我需要检查我的Windows服务吗?



这是我的代码:





guys thanks for time and help..

i have a windows services in vb.net for send emails using any host
like yahoo, gmail, internal exchange.

i have one issue my pc is in a network using isa server as proxy

when i try to send the email from windows services i get
"Unable to connect to the remote host"

but if i test the function for send email in a windows form i can send the email

what i have to check on my windows services?

this is my code:


<pre>   Public Function EmailService(ByVal Port As String, ByVal Host As String, ByVal FromEmail As String, ByVal ToEmail As String, ByVal Subject As String, ByVal Body As String, Optional EmailAtt As String = "")
        Try
            Dim SmtpServer As New SmtpClient()
            Dim key As Long
            key = "****"
            If Is64Bit() Then
                regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\Test", False)
            Else
                regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Test", False)
            End If

            Dim mysqlconn As MySqlConnection
            Dim mysqlcmd As MySqlCommand = New MySqlCommand
            Dim rd As MySqlDataReader

            Dim sqlEmailUsr As String = "SELECT ParamValue FROM userparam WHERE ParamName = 'UserEmail'"
            Dim sqlEmailPass As String = "SELECT ParamValue FROM userparam = 'UserEmailPassword'"
            Dim Email_User As String = ""
            Dim Email_Pass As String = ""

            mysqlconn = New MySqlConnection()
            mysqlconn.ConnectionString = readdbfile()

            If mysqlconn.State = Data.ConnectionState.Open Then

            Else
                mysqlconn.Open()
            End If

            Dim cmd As MySqlCommand = mysqlconn.CreateCommand()

            cmd.CommandText = sqlEmailUsr
            rd = cmd.ExecuteReader
            rd.Read()
            Email_User = rd.GetString(0).ToString
            rd.Close()

            cmd.CommandText = sqlEmailPass
            rd = cmd.ExecuteReader
            rd.Read()
            Email_Pass = rd.GetString(0).ToString
            rd.Close()

            SmtpServer.UseDefaultCredentials = False
            Dim Auth As New System.Net.NetworkCredential(Email_User, Decrypting(Email_Pass, key))
            SmtpServer.Port = Port
            SmtpServer.Host = Host
            If regKey.GetValue("Email_SSL") = "1" Then SmtpServer.EnableSsl = True
            If regKey.GetValue("Email_Auth") = "1" Then SmtpServer.Credentials = Auth
            Dim MailRecip() As String = Nothing
            Dim attachment As System.Net.Mail.Attachment
            attachment = New System.Net.Mail.Attachment(EmailAtt)
            If Trim(ToEmail.ToString) <> "" Then MailRecip = Split(Trim(ToEmail.ToString), ";")
            Dim mail As New MailMessage(New MailAddress(FromEmail.Trim()), New MailAddress(MailRecip(0)))
            If MailRecip.Length > 1 Then
                For x As Integer = 1 To MailRecip.Length - 1
                    mail.Bcc.Add(MailRecip(x))
                Next
            End If
            mail.Subject = (Subject)
            mail.Body = (Body)
            mail.IsBodyHtml = True
            mail.Priority = MailPriority.High
            mail.Attachments.Add(attachment)
            mail.ReplyToList.Add(FromEmail)
            mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess Or DeliveryNotificationOptions.OnFailure Or DeliveryNotificationOptions.Delay
            mail.Headers.Add("Read-Receipt-To", FromEmail)
            mail.Headers.Add("Disposition-Notification-To", FromEmail)
            SmtpServer.Send(mail)
            mysqlconn.Close()
        Catch ex As SmtpException
            WriteEventLogError("An error occurred Email Service: " & ex.InnerException.Message, 2000)
        End Try
        Return Nothing
    End Function





在Windows窗体上我测试这个功能,我可以使用smtp.gmail.com和yahoo或hotmail发送电子邮件。



但是在windows服务中不起作用我只能发送电子邮件给我的公司网络



on windows form i test this function and i can send email using smtp.gmail.com and yahoo or hotmail.

but in the windows services is not working only i can send email to my corporate network

推荐答案

这篇关于Vb.net Windows服务背后的isa服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆