2014-01-17 63 views
1

我有一個函數可以將創建的電子郵件發送到傳統的asp並且想要轉換asp.net Vb中的函數。首先是我的ASP功能,下面和之後,我想在VB中轉換。我做錯了什麼,以及如何在這裏閱讀我的webConfig的mailSettings。將功能從asp轉換爲asp.net發送電子郵件

Function MailIt(subject, from, email, body) 

    Dim mail As New MailMessage() 
    mail.BodyFormat = MailFormat.Html 
    mail.To = email 
    mail.From = from 
    mail.Subject = subject 
    mail.Body = body 
    mail.Bcc = "[email protected]" 
    mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.xx.com" 
    mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = "25" 'mail server port 
    mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication 
    mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") ="[email protected]" 
    mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="xxx" 
    System.Web.Mail.SmtpMail.Send(mail) 
mailit=" " 

End Function 

這我是在ASP.NET VB轉換

Public Shared Function MailIt(ByVal subject, ByVal from, ByVal email, ByVal body) 

    Dim mail As New System.Net.Mail.MailMessage() 
    mail.IsBodyHtml = True 

    mail.Body = MailFormat.Html 
    mail.To.Add(email) 
    mail.From = from 
    mail.Subject = subject 
    mail.Body = body 
    mail.Bcc = "[email protected]" 
    mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.xx.com" 
    mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = "25" 'mail server port 
    mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication 
    mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" 
    mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxx" 
    System.Web.Mail.SmtpMail.Send(mail) 
    MailIt = " " 

End Function 

回答

3

試試這個,在web.config中設置SMTP設置

Public Shared Function MailIt(ByVal subject, ByVal from, ByVal email, ByVal body) 

Dim mail As New System.Net.Mail.MailMessage() 
mail.IsBodyHtml = True 

mail.To.Add(email) 
mail.From = from 
mail.Subject = subject 
mail.Body = body 
mail.Bcc.Add("[email protected]") 

Dim smtp As SmtpClient = New SmtpClient 

smtp.Send(mailMessage) 

End Function 

web.config設置

<configuration> 
    <system.net> 
    <mailSettings> 
    <smtp from="[email protected]"> 
     <network host="smtp.yourdomain.com" port="25" userName="yourUserName" password="yourPassword"/> 
    </smtp> 
    </mailSettings> 
    </system.net> 
</configuration> 
相關問題