Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Mail

Status
Not open for further replies.

jdwm2310

Technical User
Jul 26, 2001
396
US
Hi,

I have a form, on it there is a combobox and a send button..the combobox list all the names of the user's email address when someone clicks on the email address and then clicks on send button. an email should go out to that person selected. IN addition to this i am using lotus notes. I am having a hard time in solving this i would appreciate any help..thanks
 
I use this code to send lotus notes mail from Access 97.
Hopefully somewhere in here is the answer!!

call sub with............

SendNotesMail FAO, AttachmentPath, MailTo, CCTo(), BodyTxt, True


Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, ccRecipient() As String, bodytext As String, saveit As Boolean)

''This public sub will send a mail and attachment if neccessary to the
'recipient including the body text.
'Requires that notes client is installed on the system.

On Error GoTo errHandler

'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim MultiRecip(25) As Variant ' allow multiple recipients

'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")

'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = Left(UserName, 1) & Right(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
' MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"

'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.ISOPEN = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If

' multiple recipient setup
' MultiRecip(0) = "emailaddress1"
' MultiRecip(1) = "emailaddress2"

'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
' MailDoc.sendto = MultiRecip ' multiple recipients
MailDoc.CopyTo = ccRecipient
'MailDoc.BlindCopyTo = bccRecipient
MailDoc.Subject = Subject
MailDoc.Body = bodytext
MailDoc.SAVEMESSAGEONSEND = saveit

'Set up the embedded object and attachment and attach it
If Attachment <> &quot;&quot; Then
Set AttachME = MailDoc.CREATERICHTEXTITEM(&quot;Attachment&quot;)
Set EmbedObj = AttachME.EMBEDOBJECT(1454, &quot;&quot;, Attachment, &quot;Attachment&quot;)
MailDoc.CREATERICHTEXTITEM (&quot;Attachment&quot;)
End If

'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send 0, Recipient

'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing


Exit Sub

errHandler:
' Screen.MousePointer = vbDefault
MsgBox Err.Description, vbCritical + vbOKOnly, &quot;Sending E-Mail Message&quot;

End Sub
 
wow what a code..this is the one i have...how can i incorporate this one with yours???
Private Sub Route_To_AfterUpdate()
DoCmd.SendObject acSendForm, Me.FormName, acFormatRTF, Route_To, , , (TicketNumber & &quot; is the ticket number which requires your response&quot;), &quot;Please launch the database to open the ticket.&quot;
End Sub
 
GHolden,

I don't know exactly where would I put the code you provided above...
 
Put the whole SendNotesMail sub in a module.

To send a mail use from your form call the sub with the required arguments.

eg.

SendNotesMail &quot;F.A.O. John Smith&quot;,&quot;C:\Folder\Attachment&quot;,&quot;WhoEver@WhereEver.co.uk&quot;,&quot;SomeoneElse@SomeWhere.co.uk&quot;,&quot;Hello, how are you&quot;,True


First argument is Subject
Second is attachment path if you want one
Third is e-mail address of person to send mail to
Forth is person to CC to is applicable
Fifth is Message text
Sixth is true to save in sent folder false to not

You can also pass variables.

so if the email address was in a text box (eg. txtEmail) you just pass the text box contents

eg.

SendNotesMail &quot;F.A.O. John Smith&quot;,&quot;C:\Folder\Attachment&quot;,txtEmail,&quot;SomeoneElse@SomeWhere.co.uk&quot;,&quot;Hello, how are you&quot;,True

So you could pass all of the arguments or have some set as defaults.


Hope this is a bit clearer.

 
Ok let me make sure I got this..I inserted the code you provided in a module.

In my comboboxRoute_To_AfterUpdate Event: I have this
Private Sub Route_To_AfterUpdate()
SendNotesMail (TicketNumber & &quot;is the ticket number that needs your immediate respond&quot;), Me.CurrentRecord, Route_To, , &quot;Please launch the database to view the ticket.&quot;, True
End Sub

I am getting a compile error: Argument not optional....

What am i doing wrong???
 
Sorry mine always has a CCto comment out the line

MailDoc.CopyTo = ccRecipient

and remove

ccRecipient() As String

from the sub declaration.

 
GHolden,

I did what you told me: I removed the CCRecipient()As String and MailDoc.CopyTo = ccRecipient from the sub declaration...But I am still getting a Compile Error: Arguement not Optional.....
 
Not 100% sure, it works fine for me. I don't think you need the brackets around the first argument when you call the SendNotesMail. Have you also removed the spare comma in the call, not needed now you've removed the cc argument.

Also what is the value of Me.CurrentRecord
 
It might be an idea to try it without the variables and gradually add them one by one.

eg

SendNotesMail &quot;Test&quot;,&quot;any path to a file you know exists&quot;,&quot;your email address&quot;,&quot;Hello, how are you&quot;,True

if this works change the parameters one at a time.

 
GHolden,

the value for Me.CurrentRecord is that I want to attached the current record from the form...For example I want to send record 2 which is the current record on the screen to someone....
 
Right.

The attachment part of the mail sub is expecting a file path eg. &quot;C:\Pathname\filename&quot;

if you want to sent the current record you'll need to send it as part of the message text. How is the record displayed on your form, ie. is it in textboxes etc, or in a datasheet?

 
GHolden,

I made this simple, I have no attachment I just have a message. How do I called the module you posted???? The recipient names are found in a combo box.

This is what I have in the combo box After Update event.
Private Sub Route_To_AfterUpdate()
SendNotesMail&quot;F.A.O. This ticket has been routed by the HR Help Desk&quot;,, Route_To, HRHelp!.com, &quot;Please contact &quot;&quot;Please contact the following employee: &quot; & CallerName & &quot; at : &quot; & Telephone & &quot;, after reviewing the following question: &quot; & RequestedQuestion & &quot; Thank you, &quot; & UserName&quot;,True
DoCmd.Close acForm, &quot;HelpDeskCalls&quot;, acSaveYes
DoCmd.OpenForm &quot;TicketOption&quot;
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top