Add From when sending Email using Access 2010 vba

aman

Registered User.
Local time
Yesterday, 17:52
Joined
Oct 16, 2008
Messages
1,251
Hi Guys

I want to add From in the following code so basically when we send an email using vba code then it gets sent from my office outlook email address but I infact want to send it from the "Department mailbox" e.g DirectQuery@axa.com. I am using Access 2010 but it gives me "Object doesn't support this property or method " at From statement.

Code:
 With MailOutLook
    .From = "[EMAIL="DirectQuery@axa.com"][COLOR=#000080]DirectQuery@axa.com[/COLOR][/EMAIL]"
    .To = [EMAIL="Smith@yahoo.com""]Smith@yahoo.com"[/EMAIL]
    '.To = sMailList
       .Subject = strSubject
    .Body = "Please provide an update on your outstanding actions:" & vbCrLf & vbCrLf & strBody
    .sEnd
End With

Any help will be much appreciated.
Thanks
 
You can't specify From as it's set by the local outlook account, however you can try
.SentOnBehalfOfName = "SomeoneElse@myco.com"
but the sending account will have to have permission to use the on behalf account
 
When I tried to use SentOnBehalfOfName then I got the following email back on my personal outlook email saying

You are not allowed to send this message because you are trying to send on behalf of another sender without permission to do so. Please verify that you are sending on behalf of the correct sender, or ask your system administrator to help you get the required permission.

Any other alternative to get this done?
 
No - it's an outlook/exchange thing. You have to have send permission on the account otherwise you could send from anyone's account without any comeback.

The only other way would be to use cdo mail - http://www.rondebruin.nl/win/s1/cdo.htm but this won't give you a sent copy in your outbox.
 
I tried to use CDO as below:
Code:
 Public Sub CDO_Mail_Small_Text()
MsgBox "Hello"
    Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    '    Dim Flds As Variant
     Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
     '    iConf.Load -1    ' CDO Source Defaults
    '    Set Flds = iConf.Fields
    '    With Flds
    '        .Item("[URL]http://schemas.microsoft.com/cdo/configuration/sendusing[/URL]") = 2
    '        .Item("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserver[/URL]") _
    '                       = "Fill in your SMTP server here"
    '        .Item("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserverport[/URL]") = 25
    '        .Update
    '    End With
     strbody = "Hi there" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"
     With iMsg
        Set .Configuration = iConf
        .To = "[EMAIL="rrr@axa.com"]rrr@axa.com[/EMAIL]"
        .CC = ""
        .BCC = ""
        .From = "[EMAIL="SalesDelivery@axa.com"]SalesDelivery@axa.com[/EMAIL]"
        .Subject = "New figures"
        .TextBody = strbody
        .Send
    End With
 MsgBox "Email Sent"
End Sub

But it gives me runtime error "SendUsing Configuration value is invalid"

Thanks
 
Have you actually put any values in here;
Code:
  .Item("http://schemas.microsoft.com/cdo/con...ion/smtpserver") _
    '                       = [COLOR="Red"]"Fill in your SMTP server here"[/COLOR]
You will need your SMTP servers details to be able to use CDO
 

Users who are viewing this thread

Back
Top Bottom