473,700 Members | 2,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Send mail by CDO and attachments

41 New Member
Hi, Access 2003. I have a DB that contains deadlines data. I have the DB set up to create a report for each person that has deadline within a certain time frame. I need to automate the DB so an email is sent when a report exists but an email is not sent if there is no report for people. I have CDO code that works great except for the do not send part. The following is that part of the code. Any help would be appreciated. Thanks!

Expand|Select|Wrap|Line Numbers
  1. With iMsg
  2.     Set .Configuration = iConf
  3.     .To = "bjo@propeople.org"
  4.     .CC = "bjo@propeople.org"
  5.     .From = "bjo@propeople.org"
  6.     .Subject = "Please read:  test CDOSYS message with Attachment3"
  7.     .HTMLBody = strHTML
  8.  
  9.    '.Err.Clear
  10.    On Error Resume Next
  11.    Set Object = Expression
  12.  
  13.  
  14.  
  15.    If Not IsMissing("G:\Accounting\Development\rptMiller.txt") Then
  16.          Set Attach = .AddAttachment("G:\Accounting\Development\rptMiller.txt")
  17.       End If
  18.  
  19.  
  20.      If Attach = 0 Then
  21.       Cancel = True
  22.       Else: .Send
  23.       End If
  24.  
Sep 11 '07
11 11328
pixie
41 New Member
Hi, Scott --

Thanks for all your help. I've gotten it to work. I'll attach the code.

In regard to #3, a query runs for every person that could possibly get a report. If the report is blank it doesn't save. In my code, I have one sub for each person that could get a report and the first sub calls the second sub which calls the third and so on.

I really appreciate all your help! Thanks a lot.

Expand|Select|Wrap|Line Numbers
  1. Sub FinalCDOeMail()
  2.  
  3.  
  4.  
  5.  
  6. Dim iConf
  7. Dim Flds
  8. Dim strHTML
  9. Dim Attach
  10.  
  11.  
  12.  
  13. Const cdoSendUsingPort = 2
  14.  
  15. Set iMsg = CreateObject("CDO.Message")
  16. Set iConf = CreateObject("CDO.Configuration")
  17.  
  18. Set Flds = iConf.Fields
  19.  
  20.  
  21.  
  22. With Flds
  23.     .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
  24.     'ToDo: Enter name or IP address of remote SMTP server.
  25.     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "propexbe.propeople.org"
  26.     .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
  27.     .Update
  28. End With
  29.  
  30.  
  31. strHTML = "<HTML>"
  32. strHTML = strHTML & "<HEAD>"
  33. strHTML = strHTML & "<BODY>"
  34. strHTML = strHTML & "<b><p>Please let me know if you got an attachment and if you could open it. Thanks.</p></b></br>"
  35. strHTML = strHTML & "<b><p>Also please let me know if the text of the message is bold.  Thanks.  </b></p>"
  36. strHTML = strHTML & "</BODY>"
  37. strHTML = strHTML & "</HTML>"
  38.  
  39.  
  40.  
  41. If Not Len(Dir("G:\Accounting\Development\rptMiller.txt")) = 0 Then
  42.  
  43. With iMsg
  44.     Set .Configuration = iConf
  45.     .To = "jkt@propeople.org"
  46.     .CC = "wld@propeople.org"
  47.     .From = "bjo@propeople.org"
  48.     .Subject = "Contract Reports"
  49.     .HTMLBody = strHTML
  50.  
  51.  
  52.    On Error Resume Next
  53.    Set Object = Expression
  54.  
  55.  
  56. If Not IsMissing("G:\Accounting\Development\rptMiller.txt") Then
  57.         Set Attach = .AddAttachment("G:\Accounting\Development\rptMiller.txt")
  58.       End If
  59.  
  60.  
  61.   .Send
  62.  
  63. End With
  64. End If
  65.  
  66.  
  67.  
  68.  
  69.  
  70. Set iMsg = Nothing
  71. Set iConf = Nothing
  72. Set Flds = Nothing
  73.  
  74. MsgBox "Mail Sent!"
  75.  
  76.  
  77.  
  78.  
  79.  
  80. End Sub
Sep 12 '07 #11
Scott Price
1,384 Recognized Expert Top Contributor
Hi, Scott --

Thanks for all your help. I've gotten it to work. I'll attach the code.

In regard to #3, a query runs for every person that could possibly get a report. If the report is blank it doesn't save. In my code, I have one sub for each person that could get a report and the first sub calls the second sub which calls the third and so on.

I really appreciate all your help! Thanks a lot.

Expand|Select|Wrap|Line Numbers
  1. Sub FinalCDOeMail()
  2.  
  3.  
  4.  
  5.  
  6. Dim iConf
  7. Dim Flds
  8. Dim strHTML
  9. Dim Attach
  10.  
  11.  
  12.  
  13. Const cdoSendUsingPort = 2
  14.  
  15. Set iMsg = CreateObject("CDO.Message")
  16. Set iConf = CreateObject("CDO.Configuration")
  17.  
  18. Set Flds = iConf.Fields
  19.  
  20.  
  21.  
  22. With Flds
  23.     .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
  24.     'ToDo: Enter name or IP address of remote SMTP server.
  25.     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "propexbe.propeople.org"
  26.     .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
  27.     .Update
  28. End With
  29.  
  30.  
  31. strHTML = "<HTML>"
  32. strHTML = strHTML & "<HEAD>"
  33. strHTML = strHTML & "<BODY>"
  34. strHTML = strHTML & "<b><p>Please let me know if you got an attachment and if you could open it. Thanks.</p></b></br>"
  35. strHTML = strHTML & "<b><p>Also please let me know if the text of the message is bold.  Thanks.  </b></p>"
  36. strHTML = strHTML & "</BODY>"
  37. strHTML = strHTML & "</HTML>"
  38.  
  39.  
  40.  
  41. If Not Len(Dir("G:\Accounting\Development\rptMiller.txt")) = 0 Then
  42.  
  43. With iMsg
  44.     Set .Configuration = iConf
  45.     .To = "jkt@propeople.org"
  46.     .CC = "wld@propeople.org"
  47.     .From = "bjo@propeople.org"
  48.     .Subject = "Contract Reports"
  49.     .HTMLBody = strHTML
  50.  
  51.  
  52.    On Error Resume Next
  53.    Set Object = Expression
  54.  
  55.  
  56. If Not IsMissing("G:\Accounting\Development\rptMiller.txt") Then
  57.         Set Attach = .AddAttachment("G:\Accounting\Development\rptMiller.txt")
  58.       End If
  59.  
  60.  
  61.   .Send
  62.  
  63. End With
  64. End If
  65.  
  66.  
  67.  
  68.  
  69.  
  70. Set iMsg = Nothing
  71. Set iConf = Nothing
  72. Set Flds = Nothing
  73.  
  74. MsgBox "Mail Sent!"
  75.  
  76.  
  77.  
  78.  
  79.  
  80. End Sub
Great! Glad you got it to work! The funny thing is that your solution is exactly what I thought it should be in the first place, and was going to follow up with the next post... You beat me to it :-) Good job!

Regards,
Scott
Sep 12 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1513
by: mimi | last post by:
Hi, I've been searching all the posts and articles but couldn't find any example on how to send attachments with pop3 using C#. Does anyone have one or know how? Thanks
3
3709
by: Luiz Vianna | last post by:
Guys, I have a Windows 2003 running Exchange 2003. On this machine I'm trying to run an ASP.NET webform to send an e-mail. The codebehing my ASPX is like this: Dim NewMail As New CDO.Message NewMail.From = From NewMail.To = Msgto
1
1793
by: Sophie | last post by:
Hi, I'm not very good in english so excuse me if I have difficulty to explain my problem. I want to send a mail with VB.net with this code : Option Strict On Public Class Form1 Inherits System.Windows.Forms.Form
2
10693
by: Landley | last post by:
Hello, Is there a way of creating an email, attaching a file and sending using the client's default mail client? I am looking for a none email client specific solution that does not involve specifying parameters such as mail servers etc. Cheers,
2
3888
by: Husam | last post by:
Hi EveryBody: I made windows application project as e-mail sender. This project consist of 13 textbox and one label and one button. I add {system.web.dll} as refrance to this project to help me using some mail functions after I got hint from Mr. Paul Remblance to do so. The code is like the follwoing: Imports System.Web.Mail
2
2496
by: Robert Dufour | last post by:
I tried using (vs2003 Vb.Net) Public Sub SendEmail( _ ByVal Recipient As String, _ ByVal Sender As String, _ ByVal Subject As String, _ ByVal Message As String, _
2
2646
by: oyster | last post by:
I find that the existing email moudle is some hard for me to understand, especially the part of how to set the CC, BCC and attach the files. Is there any more easy one like this p-code? import easyemail smtpserver=easyemail.server('something') smtpserver.login('usr@gmail.com', pwd) newletter=smtpsever.letter(smtpserver) newletter.sendto= newletter.sendcc=
1
2413
by: Chitu03 | last post by:
Hi I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know how can i get from database and then add to my mail. <?php function send_mail($emailaddress, $fromaddress, $emailsubject, $body, $ccaddress, $attachments=false) { $eol="\r\n"; $mime_boundary=md5(time()); # Common Headers $headers .= 'From:...
1
6843
by: maxxxxel | last post by:
Hi Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine. Our problem is that when we send mail externally to a internet email site like Gmail the PDF is sent but is corrupted because CDOSYS ends up using binary encoding rather than Base64 encoding when creating the attachment. More information here: Anthonys Code My knowledge of ASP...
1
6561
by: sxwend | last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the results to just the email addresses that the query specifies for each record... Essentially this is a make shift Ordering Tool and I want to be able to notify the receiver of the order and its specifics. q_Order_Detail_4email consists of ,,, and Example: Hello@mail.com,956,Modem,1000,xyz123...
0
8716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9204
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7799
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6557
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4650
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2021
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.