Home All Groups Group Topic Archive Search About

Sending email from Windows application Not working.

Author
30 Aug 2006 3:41 PM
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




---------------
Does anybody have any idea?

Thanks

Author
30 Aug 2006 4:30 PM
xin.yadong@gmail.com
When I use the following function to test the SMTP server, it return
true in web app but return false in Win app.
My Test PC is XP pro.

Public Shared Function DetectSMTPServer( _
             Optional ByVal host As String = "XXX") _
             As Boolean
        Dim tcp As New System.Net.Sockets.TcpClient
        Dim ServerExists As Boolean = False
        Try
            tcp.Connect(host, 25)
            ServerExists = True
        Catch ex As Exception
            ServerExists = False
        Finally
            tcp.Close()
        End Try
        Return ServerExists
    End Function