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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can this be done for mailing via Access 2003?

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
US
I have been asked to create a database that will function as a mailmerge. What it will do is:

1> Use templates to create emails
2> Create word/excel documents to send as attachments

What I want to know is can this be intergrated with our Microsoft Exchange server instead of directly through the SMTP server. I would like to see that it can integrate with Microsoft Exchange so I would not have to know the SMTP email address, it can take the exchange email address and send via Microsoft Exchange. The reason is because we have had various instances that the smtp address has changed.

if this can be done, does anyone have any examples or links they can post to point me in the right direction?

Thanks
 
Your lucky day, I did just this last week!


Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim wrdSelection As Word.Selection

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strBody As String
Dim strSub As String
Dim strEmail As String
Dim strSig As String

'Start with the desired text
strSub = "Regarding what your text is regarding"
strBody = "A lot of text to type in here..."
strSig = "From the person who sent this"

'Set database connection
Set db = CurrentDb
strSQL = "SELECT FROM tbl_tbl"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)

'Start getting addresses
rs.MoveFirst
Do Until rs.EOF

'Put the contacts email address into the placeholder for "To" field
strEmail = rs.Fields(0).Value

'If its a valid email address send to it
If (InStr(strEmail, "@") > 0) Then
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = strEmail
.Subject = strSub
.Body = strBody
.FlagIcon = 1
.Importance = 2
.Attachments.Add "Document.pdf"
.Send
End With
Set objEmail = Nothing

' Otherwise create an instance of Word
Else
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False

' Open the blank document.
Set wrdDoc = wrdApp.Documents.Open("Blank Letter.dot")
wrdDoc.Select
Set wrdSelection = wrdApp.Selection

' Insert a date field with the current date, right aligned.
With wrdSelection
.TypeParagraph
.ParagraphFormat.Alignment = 2
.InsertDateTime DateTimeFormat:="dddd, MMMM dd, yyyy", _
InsertAsField:=False, _
DateLanguage:=wdEnglishUS, _
CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
.TypeParagraph
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.TypeParagraph
End With

'Write the body of the letter
wrdSelection.TypeText strEmail & vbCr & strBody & vbCr & strSig

'Save the document as the company name and close Word, cleaning up references
wrdDoc.SaveAs ("Snailmail to " & strEmail & ".doc")
wrdDoc.Close True
Set wrdSelection = Nothing
Set wrdDoc = Nothing
Set wrdApp = Nothing
End If
rs.MoveNext
Loop
End Sub
 
Can this be used to interface with exchange server instead of with an SMTP server? also when access uses this send mail feature can it be used to send say like send on behalf? This way you are not sending as yourself, but maybe has a group mailbox?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top