简体   繁体   English

使用VB代码发送电子邮件仅在本地有效,而不能从Web服务器发送

[英]Sending email using VB code only works locally not from webserver

I am using the code below to generate an email and it works fine locally in development but when I try it over the web it does not work? 我正在使用下面的代码生成电子邮件,并且在开发中可以在本地正常工作,但是当我通过网络尝试时,它不能正常工作吗? Do I need to do something different or can this not be accomplished over the web using it this way? 我是否需要做一些不同的事情,还是不能以这种方式在网络上完成?

 Try


    Dim mailMessage As MailMessage = New MailMessage
    mailMessage.From = New MailAddress("Test@whatever.com")
    'mailMessage.Subject = txtSubject.Text.Trim
    'mailMessage.Body = txtBody.Text.Trim
    mailMessage.IsBodyHtml = True
        mailMessage.To.Add(New MailAddress("Test@whatever.com"))
    ' Dim files As List(Of HttpPostedFile) = CType(Session("Files"), List(Of HttpPostedFile))
    'For Each file As HttpPostedFile In files
    mailMessage.Attachments.Add(New Attachment("\\Server\test.pdf"))
    'Next

    Dim smtp As SmtpClient = New SmtpClient

    smtp.Host = "Mail.com"

        'smtp.EnableSsl = True

    Dim NetworkCred As System.Net.NetworkCredential = New System.Net.NetworkCredential
    smtp.UseDefaultCredentials = True
    smtp.Send(mailMessage)
    Catch ex As Exception

    End Try

您是否在使用网络凭据,例如SMTP服务器可能需要的凭据?

smtp.Credentials = new NetworkCredential(USERNAME, PASSWORD);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM