X
xin.yadong
Hi:
I have a shared function for sending Email using SMTP.
It works fine in a ASP.NET web application. But when I use it in a
VB.Net Windows application, it always gave me an error: "Could not
access 'CDO.Message' object."
I am runing both Web and Windows App on same test PC, and SMTP server
is hosted on another machine.
The function for sending Email is:
Public Shared Function SendEmail(ByVal email_From As String, _
ByVal email_To As String, _
ByVal email_Subject As String, _
ByVal email_Body As String, _
Optional ByVal email_CC As String = "", _
Optional ByVal email_BCC As String = "", _
Optional ByRef email_AttachmentList As
System.Collections.IList = Nothing)
Dim email As New System.Web.Mail.MailMessage
email.From = email_From
email.To = email_To
email.Subject = email_Subject
email.Body = email_Body
email.Cc = email_CC
email.Bcc = email_BCC
email.BodyFormat = Web.Mail.MailFormat.Text
If Not email_AttachmentList Is Nothing Then
email.Attachments.Add(email_AttachmentList)
End If
Try
System.Web.Mail.SmtpMail.SmtpServer = "SMTP_XXX"
System.Web.Mail.SmtpMail.Send(email)
Catch ex As Exception
Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(ex)
End Try
End Function
I have a shared function for sending Email using SMTP.
It works fine in a ASP.NET web application. But when I use it in a
VB.Net Windows application, it always gave me an error: "Could not
access 'CDO.Message' object."
I am runing both Web and Windows App on same test PC, and SMTP server
is hosted on another machine.
The function for sending Email is:
Public Shared Function SendEmail(ByVal email_From As String, _
ByVal email_To As String, _
ByVal email_Subject As String, _
ByVal email_Body As String, _
Optional ByVal email_CC As String = "", _
Optional ByVal email_BCC As String = "", _
Optional ByRef email_AttachmentList As
System.Collections.IList = Nothing)
Dim email As New System.Web.Mail.MailMessage
email.From = email_From
email.To = email_To
email.Subject = email_Subject
email.Body = email_Body
email.Cc = email_CC
email.Bcc = email_BCC
email.BodyFormat = Web.Mail.MailFormat.Text
If Not email_AttachmentList Is Nothing Then
email.Attachments.Add(email_AttachmentList)
End If
Try
System.Web.Mail.SmtpMail.SmtpServer = "SMTP_XXX"
System.Web.Mail.SmtpMail.Send(email)
Catch ex As Exception
Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(ex)
End Try
End Function