2010-02-09 54 views

回答

0

這是我用於我的應用程序的代碼,它用於ASP.NET。您需要在班級頂部爲.net.mail進行導入。 - >進口System.Net.Mail


Public Sub SendEmail(ByVal Sentfrom As String, ByVal Recipient As String, _ ByVal SubjectLine As String, ByVal Messagebody As String)

Dim SmtpEngine As New SmtpClient SmtpEngine.Host = "yourhost.com" Try SmtpEngine.Send(Sentfrom & "@taco.com", Recipient & "@taco.com", SubjectLine, Messagebody) Catch ex As Exception My.Application.Log.WriteException(ex) End Try End Sub

0

試試這個功能:

Public Sub SendMsg(from, dest, subj, body) 
    Dim msg, flds, conf 

    Set msg = CreateObject("CDO.Message") 
    Set conf = CreateObject("CDO.Configuration") 
    Set flds = conf.Fields 

    flds(cdoSendUsingMethod) = cdoSendUsingPort 
    flds(cdoSMTPServer) = "smtp.xyz.org" 
    flds(cdoSMTPServerPort) = 25 

'if use SMTP authentication... 
     flds(cdoSMTPAuthenticate) = cdoBasic 
     flds("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxxx" 
     flds("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "zzzzzz" 
    '... or, without SMTP authentication 
     flds(cdoSMTPAuthenticate) = cdoAnonymous 

    flds.Update 

    On Error Resume Next 
    With msg 
     Set .Configuration = conf 
     .BodyPart.CharSet = "utf-8" 
     .TextBodyPart.CharSet = "utf-8" 
     .To = dest 
     .From = from 
     .Subject = subj 
     .TextBody = body 
     .Send 
    End With 
    On Error Goto 0 

    set msg = nothing 
    set conf = nothing 
    set flds = nothing 
End Sub 
相關問題