Sending email from Windows application Not working.

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
 
X

xin.yadong

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top