Results 1 to 2 of 2

Thread: SendMail: CDO.Message

  1. #1

    Thread Starter
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    SendMail: CDO.Message

    I'm having a little difficulty sending mail using VB.Net (2003). I'm attempting to use the company mailhost, and the usual System.Mail methods to do the send, but i get blocked by the "Could not create CDO.Message" error.

    I've been on MSDN, and looked through the various threads on here, and they all point to a problem with the dll.

    The trouble is, that this is not a consistent error. Sometimes it works, sometimes it doesn't. It will work on one user's PC profile, but not another's on the same PC. It will send a mail for a particular user, and then 2 mins later fail to send the same mail.
    I've tried re-registering the dll anyway, and faffing about in the registry as per the MSDN recommendation, but no joy. And because it's so inconsistent it's proving pretty tricky to narrow down the cause.


    Any suggestions?
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  2. #2
    Lively Member
    Join Date
    Jun 2008
    Location
    Bweeng, Ireland
    Posts
    69

    Re: SendMail: CDO.Message

    Hi,

    I know this doesn't address the CDO issue but here is a function I use to send mails.

    Don't forget to "Imports System.Net.Mail".

    AdminEmailSettings is defined by

    Code:
        Structure EmailSettings
            Dim ToAddress As String
            Dim FromAddress As String
            Dim EmailUsername As String
            Dim EmailPassword As String
            Dim EmailSMTP As String
        End Structure
    Code:
        Private Sub SendEmail(ByVal EmailAddresses As String, ByVal Subject As String, ByVal Body As String, ByVal Attachment As String)
            Dim smtp As New SmtpClient(AdminEmailSetting.EmailSMTP.ToString)
            Dim mail As New MailMessage, Email() As String, EmailAddress As String
            Dim FileName As String = ""
    
            ' Connect to the database
            Try
                'set the addresses
                mail.From = New MailAddress(AdminEmailSetting.FromAddress.ToString)
                ' Do not change as relaying is not allowed
                mail.Sender = New MailAddress(AdminEmailSetting.FromAddress.ToString)
                mail.ReplyTo = New MailAddress(AdminEmailSetting.FromAddress.ToString)
                ' Add the TO email addresses
                Email = Split(EmailAddresses, ";")
                For Each EmailAddress In Email
                    If EmailAddress <> "" Then
                        mail.To.Add(EmailAddress)
                    End If
                Next
                'set the content
                mail.Subject = Subject
                mail.IsBodyHtml = False
    
                ' Attachment
                If Attachment.ToString.Trim.Length <> 0 Then
                    Dim MyAttachment As New System.Net.Mail.Attachment(Attachment)
                    mail.Attachments.Add(MyAttachment)
                End If
    
                If Body.ToString.Trim.Length <> 0 Then
                    mail.Body = Body.ToString
                End If
                'send the message
                'to authenticate we set the username and password properites on the SmtpClient()
                With smtp
                    If Not Attachment.ToString.Length = 0 Then
                        Dim fileDetail As IO.FileInfo
                        fileDetail = My.Computer.FileSystem.GetFileInfo(Attachment.ToString)
    
                        If fileDetail.Length > 1000000 Then
                            .Timeout = 1000 * 60 * 10
                        Else
                            .Timeout = 100000
                        End If
                    Else
                        .Timeout = 100000
                    End If
    
                    .Credentials = New Net.NetworkCredential(AdminEmailSetting.EmailUsername.ToString, AdminEmailSetting.EmailPassword.ToString)
                    .Send(mail)
                End With
    
    
            Catch ex As Exception
                ' Ignore
            Finally
                mail = Nothing
                smtp = Nothing
            End Try
        End Sub
    Hope this gives you another option.
    Jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width