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

时间:2013-07-19 20:40:42

标签: asp.net vb.net email smtp

我正在使用下面的代码生成一个电子邮件,它在开发中本地工作正常,但是当我在网上试用它时它不起作用?我是否需要做一些不同的事情,或者这是不是可以通过这种方式在网上完成?

 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

1 个答案:

答案 0 :(得分:0)

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

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