代码之家  ›  专栏  ›  技术社区  ›  zeroef

无法建立连接,因为目标计算机主动拒绝了它

  •  0
  • zeroef  · 技术社区  · 15 年前

    sch = "http://schemas.microsoft.com/cdo/configuration/" 
                    Set cdoConfig = CreateObject("CDO.Configuration") 
    
                        With cdoConfig.Fields 
                            .Item(sch & "sendusing") = 2 
                            .Item(sch & "smtpserver") = "mail.mydomain.com" 
                            .update 
                        End With 
    
                    Set cdoMessage = CreateObject("CDO.Message") 
    
                        strTo = "toaddr@mydomain.com"
    
                    strFrom = "fromaddr@mydomain.com"
    
                    strSubject = "email subject"
                    strBody = strBody & "This is the email body"
    
    
                    With cdoMessage 
                            Set .Configuration = cdoConfig 
                            .From = strFrom
                            .To =  strTo
                            .Subject = strSubject
                            .HTMLBody = strBody
                            .Send 
                    End With
    
                    Set cdoConfig = Nothing
                    Set cdoMessage = Nothing
    

    我的web.config 设置:

    <system.net>
        <mailSettings>
            <smtp from="myemail@mydomain.com">
                <network host="mail.mydomain.com" port="2"/>
            </smtp>
        </mailSettings>
    </system.net>
    

            Dim mailmsg As New MailMessage("myemail@mydomain.com", txtSubmitterEmail.Text)
    
            mailmsg.Subject = "subject here"
            mailmsg.Body = "mail body here"
            mailmsg.IsBodyHtml = True
    
            Dim smtp As New SmtpClient
    
            smtp.Send(mailmsg)
    

    1 回复  |  直到 14 年前
        1
  •  3
  •   Matt Stephenson    15 年前

    您要访问的SMTP服务器可能位于端口25上。

    <network host="mail.mydomain.com" port="25"/>
    

    这与 sendusing

    推荐文章