Anybody good wih VB code?
07-06-2006, 15:05
|
#1
|
|
Guest
Location: Near Hungerford, West Berkshire
Services: TV: Sky HD, Landline: BT,
Mobile: Orange, Internet: Quite Slow!
Posts: n/a
|
Anybody good wih VB code?
Anybody here good with VB code?
One of my customers is trying to send out some mailshot using MS Access with intergrates with Outlook to send the email.
They don't want the email to be from internalemployeename@company.co.uk but to use enquiries@company.co.uk.
The code I have been given is like this:
Quote:
Sub SendMessages(Optional AttachmentPath)
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("tblMailingList")
MyRS.MoveFirst
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Do Until MyRS.EOF
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
TheAddress = MyRS![strEmailAddress]
With objOutlookMsg
' Add the To recipients to the e-mail message.
Set objOutlookRecip = .Recipients.Add(TheAddress)
objOutlookRecip.Type = olTo
' Add the Cc recipients to the e-mail message.
'If (IsNull(Forms!frmMail!CCAddress)) Then
'Else
' Set objOutlookRecip =
.Recipients.Add(Forms!frmMail!CCAddress)
' objOutlookRecip.Type = olCC
'End If
' Set the Subject, the Body, and the Importance of the e-mail message.
.Subject = Forms!frmMail!strSubject
.Body = Forms!frmMail!strText
.Importance = olImportanceHigh 'High importance
'Add the attachment to the e-mail message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve the name of each Recipient.
'For Each objOutlookRecip In .Recipients
' objOutlookRecip.Resolve
' If Not objOutlookRecip.Resolve Then
' objOutlookMsg.Display
' End If
'Next
.Send
End With
MyRS.MoveNext
|
My question is - is there a string of code which they can add /change so the email forced out with the senders address as enquiries@company.co.uk?
Thanks for the advice!
|
|
|
|
07-06-2006, 15:25
|
#2
|
|
Inactive
Join Date: Jun 2003
Posts: 1,354
|
Re: Anybody good wih VB code?
hmm i am sure you can set a .From in the Oulook object...
left my program days a while back so am not 100%
Edit:
I know it sounds crazy but before
Quote:
|
.Subject = Forms!frmMail!strSubject
|
put
does it work :oooo
EDIT:
I suck
|
|
|
07-06-2006, 15:33
|
#3
|
|
Inactive
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
|
Re: Anybody good wih VB code?
Nah you can't do that with from. you have to use .SentOnBehalfOfName
|
|
|
07-06-2006, 15:36
|
#4
|
|
Guest
Location: Near Hungerford, West Berkshire
Services: TV: Sky HD, Landline: BT,
Mobile: Orange, Internet: Quite Slow!
Posts: n/a
|
Re: Anybody good wih VB code?
So write it like this:
.Subject = Forms!frmMail!strSubject
.From = enquiries@company.co.uk
...with the .From entry directly under the .Subject??
Correct?
---------- Post added at 15:36 ---------- Previous post was at 15:34 ----------
Quote:
|
Originally Posted by gazzae
Nah you can't do that with from. you have to use .SentOnBehalfOfName
|
Can you give me that in actual code please? ie where it needs to go within the code?
My coding skills are krap!!
Thanks
Lee
|
|
|
|
07-06-2006, 15:36
|
#5
|
|
Inactive
Join Date: Jun 2003
Posts: 1,354
|
Re: Anybody good wih VB code?
Quote:
|
Originally Posted by gazzae
Nah you can't do that with from. you have to use .SentOnBehalfOfName
|
ok so like .SentOnBehalfOfName = enquiries@company.co.uk ?
|
|
|
07-06-2006, 15:37
|
#6
|
|
Inactive
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
|
Re: Anybody good wih VB code?
.SentOnBehalfOfName = "enquires@company.com"
|
|
|
07-06-2006, 15:40
|
#7
|
|
Inactive
Join Date: Jun 2003
Posts: 1,354
|
Re: Anybody good wih VB code?
So make you bit above say:
Quote:
.SentOnBehalfOfName = "enquires@company.com"
.Subject = Forms!frmMail!strSubject
.Body = Forms!frmMail!strText
.Importance = olImportanceHigh 'High importance
|
|
|
|
07-06-2006, 15:42
|
#8
|
|
Inactive
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
|
Re: Anybody good wih VB code?
Yep pretty much.
Are you using exchange? If you have any problems you might need to check the permissions on the mailbox to let you send mail on behalf of others. IIRC.
|
|
|
07-06-2006, 15:51
|
#9
|
|
Guest
Location: Near Hungerford, West Berkshire
Services: TV: Sky HD, Landline: BT,
Mobile: Orange, Internet: Quite Slow!
Posts: n/a
|
Re: Anybody good wih VB code?
Wicked - thanks!
I'll pass it onto the customer and see what happens....
Will let you know tomorrow morning...
---------- Post added at 15:51 ---------- Previous post was at 15:42 ----------
Quote:
|
Originally Posted by gazzae
Yep pretty much.
Are you using exchange? If you have any problems you might need to check the permissions on the mailbox to let you send mail on behalf of others. IIRC.
|
Yep - but it's not a mailbox - it's a DL. I've given delagte permissions on the DL - I think ....err I hope!
|
|
|
|
07-06-2006, 16:10
|
#10
|
|
cf.mega poster
Join Date: Dec 2003
Age: 51
Posts: 7,101
|
Re: Anybody good wih VB code?
Yep, gazzae is spot-on.  For security reasons (to stop people spoofing from addresses ...although it can be done anyway, just not in VB) you have to use .SentOnBehalfOfName()
More info, and some snippets of code here - http://support.microsoft.com/?kbid=232309
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 11:45.
|