Avatar of craZcoder
craZcoder asked on

Sending X400 mails using CDO

Hi,
I m using CDOEx for sending mails. It works fine for SMTP addresses, but doesnt work for X400 address.
Here is a sample X400 address.
[X400:c=us;a= ;p=sss;o=chn;s=sysexhwnt;]
The problem with CDO is, it treats the above as a SMTP address and tries to separate it into different IDs at the semi-colons.
Do you know any properties to specify that the address is an X400 or LDAP or SMTP address inorder to avoid this parsing?
I am not sure where to put this query, since I m using VB, hence I have put it here. Let me know if I need to put it elsewhere.
Thanks in advance,
Z.

Visual Basic Classic

Avatar of undefined
Last Comment
craZcoder

8/22/2022 - Mon
iozturk

X400 mails are different from smtp's. To send x400 mails you need to logon to the exchange server before sending it.

Here is an example that works for logon user account
add dont forget to add micsosoft CDO library from references.

Private sub fSendMail()
  Dim objsession As mapi.Session
  Dim objmessage As mapi.Message
  Dim objnewAttachment, objOneRecip
  Dim file_name, file_path
  Dim fso As Scripting.FileSystemObject
 

  On Error Resume Next
   
    If Err.Number <> 0 Then
        fSendMail = False
        Exit Function
    End If
   Set objsession= CreateObject("MAPI.Session")
   bstrProfileInfo = server + vbLf + kulemailx
   'change the parameters to valid values for your   configuration
   objsession.Logon , , , True, , True, bstrProfileInfo
    ' create a message and fill in its properties
    Set objmessage = objsession.Outbox.Messages.Add    
    objmessage.Subject = konu + " (Helpdesk)"
    objmessage.Text = mesaj + vbCrLf + CStr(Now)
    file_name = objability.fFindAttachment(pno)
    'writelog file_name
    If file_name <> "0" Then
       Set fso = CreateObject("scripting.Filesystemobject")
       If fso.FileExists(UploadPath + file_name) Then
           Set objnewAttachment = objmessage.Attachments.Add
           objnewAttachment.Name = file_name
           objnewAttachment.Source = UploadPath + file_name
           objnewAttachment.Type = 1
           objnewAttachment.ReadFromFile (UploadPath + file_name)
       End If
       Set fso = Nothing
    End If

    'create the recipient
    Set objOneRecip = objmessage.Recipients.Add
    objOneRecip.Name = isim
    'objOneRecip.Type = CdoTo
    objOneRecip.Resolve ' get MAPI to determine complete e-mail address
 
    ' send the message and log off
    If kulgrup = 5 Then
        objmessage.DeliveryReceipt = True
        objmessage.ReadReceipt = True
    End If
    objmessage.Send False, False, 0
       
    If Err.Number <> 0 Then
        ' log it
    End If
   

End Function
iozturk

sorry, you need some modifications on that. here is it

Private sub fSendMail(file_name)
  Dim objmessage As mapi.Message
  Dim objnewAttachment, objOneRecip
  Dim file_name, file_path
  Dim fso As Scripting.FileSystemObject
 
  On Error Resume Next


   
    If Err.Number <> 0 Then
        fSendMail = False
        Exit Function
    End If
    Set mysession = CreateObject("MAPI.Session")
    bstrProfileInfo = server + vbLf + "yourusername" 'take user name from wscript.network
   'change the parameters to valid values for your configuration
    mysession.Logon , , , True, , True, bstrProfileInfo

    ' create a message and fill in its properties
    Set objmessage = objsession.Outbox.Messages.Add
   
    objmessage.Subject = "ypur subject"
    objmessage.Text = mesaj + vbCrLf + CStr(Now)
       
    If file_name <> "0" Then
       Set fso = CreateObject("scripting.Filesystemobject")
       If fso.FileExists(UploadPath + file_name) Then
           Set objnewAttachment = objmessage.Attachments.Add
           objnewAttachment.Name = file_name
           objnewAttachment.Source = UploadPath + file_name
           objnewAttachment.Type = 1
           objnewAttachment.ReadFromFile (UploadPath + file_name)
       End If
       Set fso = Nothing
    End If

    'create the recipient
    Set objOneRecip = objmessage.Recipients.Add
    objOneRecip.Name = "recipientusername"
    'objOneRecip.Type = CdoTo
    objOneRecip.Resolve ' get MAPI to determine complete e-mail address
 
    ' send the message and log off
   
    objmessage.DeliveryReceipt = True
    objmessage.ReadReceipt = True
   
    objmessage.Send False, False, 0
       
    If Err.Number <> 0 Then
        ' log it
    End If
   

End Sub
ASKER
craZcoder

Thanks iozturk for the post. This works, however I need to use CDOEx only as per the design specification. Can you tell me if this is possible?
Also I need to attach some .log files and rename them before sending the mail. The problem is when I try to rename the file say Error.Log, it is changed to error.log.dat.
Any ideas?

Thanks,
Z.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
craZcoder

Better still, can anyone tell me how to convert legacy addresses (X400, LDAP, DN etc) to SMTP address?

Thanks!!
Z.
CleanupPing

craZcoder:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
ASKER CERTIFIED SOLUTION
iozturk

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
craZcoder

I hv given the points to iozturk, even though my question was not answered completely.
Thanks,
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.