Results 1 to 8 of 8

Thread: Need help sending email using Exchange

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Need help sending email using Exchange

    Can someone please provide an example of code needed (or point me to a thread) that I could use to send email from a Scheduled Task. The task runs Excel and Access routines and I would like to send email notifications to certain people regarding job status. We are using Microsoft Exchange on our server. Also, what information do I need to have regarding server name, IP's, etc? This is my first time sending email so please give as much information as you can.

    Thank you very much for any help you can provide.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Need help sending email using Exchange

    you can automate outlook if the users have it installed and configured

    personally i would use cdo.message, which runs in background with no user intervention required, and is available on all machines since win 2000

    there is also vbsendmail that is free to download and use

    the are many threads, in this and vb6 forum, with full sample code for all of the above

    there is also vb6 mapi controls, but would not recommend them to use now, as they require a mapi enabled email client to be installed and configured
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Need help sending email using Exchange

    Thanks for reply. I am trying to use CDO but I can't get it to work using Exchange; e.g. what do i use for 'smtpserver', 'sendusing', 'smtpserverport'?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Need help sending email using Exchange

    you should be able to use the same server and port information from your email client

    if you do not set any values for those, it should use your default settings, the same as your default email client
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Need help sending email using Exchange

    Thanks for trying to help, Pete. I'm not making any progress on this.

    Here is the code that works on my desktop, where I'm using Outlook:

    Code:
    Email_Subject = "Trying to send email using CDO"
    Email_Send_From = "[email protected]"
    Email_Send_To = "[email protected]"
    Email_Body = "Congratulations!!!! You have successfully sent an e-mail using CDO"
    
    Set CDO_Mail_Object = CreateObject("CDO.Message")
    Set CDO_Config = CreateObject("CDO.Configuration")
    CDO_Config.Load -1
    Set SMTP_Config = CDO_Config.Fields
    With SMTP_Config
    .Item("......//schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("......//schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.charter.net"
    .Item("......//schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Update
    End With
    With CDO_Mail_Object
    Set .Configuration = CDO_Config
    End With
    CDO_Mail_Object.Subject = Email_Subject
    CDO_Mail_Object.From = Email_Send_From
    CDO_Mail_Object.To = Email_Send_To
    CDO_Mail_Object.TextBody = Email_Body
    
    CDO_Mail_Object.send
    The error I get in this case is something like: server rejected one or more recipients (8004020F)

    'Name' is this case would be my username. I have to email providers, one with Yahoo and another with Charter Communications, my internet provider. I have remote sign on acess to the server but I do not have an email account there. Maybe that's the problem. Also, the server uses Microsoft Exchange and I am accustomed to using Outlook. There are other parameters that CDO uses that may be needed, like server name, port, etc. that I am not sure of. Can you tell me what parameters would be necessary and where on the server I can find them, or what should I ask of the site administrator?

    Thanks again for helping.

    Ed

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Need help sending email using Exchange

    More information. I'm learning. If I change the smptserver to the IP of the exchange server, or the server's name, and change both the sendfrom and the sendto to an email address of a person who has an email account on the server, then they do get the email. But when I change either the sendfrom or sendto to any of my own email addresses, then I get the 8004020F - Unable to relay error.

    Does that mean that I need to have an email account on the server (which doesn't make sense to me), or do I have to have some other authentication information because I'm asking CDO to send an email on someone else's behalf?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Need help sending email using Exchange

    More info. I can now send email on this server from myself (Gmail) to myself. What I need to do is send an email from a person who has an email account on the server to others on the server and to myself.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Need help sending email using Exchange

    as you have found out, many (but not all) smtp servers do not allow none registered senders, or spoofing of from email addresses, seems more severs are tightening up on this anyway, so better to say it can not be done anyway, also many ISPs block port 25 so emails can not be sent, through other mail servers that use port 25

    if you do not set values for smtp server, port or sender, it should use the default that is used by the default email client, as i do not have an exchange server here i can not test this, but it does work with my ISP smtp server, but as every users settings differ, there would be no guarantee that all would work correctly,
    having a special gmail account for your program, for all users, is one work around, but any message sent as reply to: would go back to the gmail account
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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