Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_cdo thread: Unable to send external mail using CDONTS


Message #1 by "Diwakar Dewan" <axyl99@y...> on Mon, 22 Apr 2002 17:00:17
I am using the following code in Visual Basic on a Win 2000 workstation. I 
am able to send emails to only internal email addreses but not any 
external address. Can anyone help me with this. Do I need to have the 
ports open to send any external email.

---

Set MYMail = CreateObject("CDONTS.NewMail")

MYMail.From = "abc@x..."
MYMail.To = "sss@y..."
MYMail.Subject = "Testing"
MYMail.BodyFormat = CdoBodyFormatHTML
MYMail.MailFormat = CdoMailFormatMime
MYMail.Body = "Hi this is a test mail"
MYMail.Send

Set MYMail = Nothing

---

I am able to send emails to external addresses using the following code- 


Dim objSession As Object  ' or Dim objSession As MAPI.Session
Dim objMessage As Object  ' or Dim objMessage As Message
Dim objOneRecip As Object ' or Dim objOneRecip As Recipient
 
 
' create a session then log on, supplying username and password
Set objSession = CreateObject("MAPI.Session")
' change the parameters to valid values for your configuration
objSession.Logon "usrname", "", False, False
 
' create a message and fill in its properties
Set objMessage = objSession.Outbox.Messages.Add
 
' create the recipient
Set objOneRecip = objMessage.Recipients.Add
objOneRecip.Name = "xyz@y..."
objOneRecip.Type = CdoTo

objOneRecip.Resolve
  
With objMessage ' message object
    .Subject = "attachment test"
    .Text = " This is a test msg"
    .Update ' update message to save attachment in MAPI system
End With
     
' send the message and log off
objMessage.Send showDialog:=False
'MsgBox "The message has been sent"
objSession.Logoff
Exit Sub

  Return to Index