Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    San Francisco, California, USA
    Posts
    358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sending an Outlook Email (From) (Office XP)

    Hi All!

    I am using the code from the MS site to automatcially create an outlook email from Access. What I can't find is how to automatically set the From address. The code for sending To someone looks like this:

    Set objOutlookRecip = .Recipients.Add("This Person")
    objOutlookRecip.Type = olTo

    Does anyone know how to set the From field in the Outlook message?

    As a side question, I'm also trying to build my message body with attachments in the middle of it (For example, Do bla bla bla with this file <attachment>, then to bla with this file<attachment>), instead of attachments at the end. I've tried splitting up the email and putting the attachments throughout, but they always appear at the end.

    Any suggestions are highly appreciated!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sending an Outlook Email (From) (Office XP)

    For security reasons, you cannot set the From address (think of the consequences!)
    But if you have Delegate permissions for another user, you can set the SentOnBehalfOfName property of the MailItem object.

    With objMailItem
    Set objOutlookRecip = .Recipients.Add("This Person")
    objOutlookRecip.Type = olTo
    .SentOnBehalfOfName = "That Person"
    End With

    The Attachment object has a property Position. This is a number that indicates the position of the attachment in the body of the mail item. You would have to keep track of the length of the text you use as body text.
    Note: this is only useful if you send mail in Rich Text Format (RTF). In HTML and Plain Text format, attachments are always displayed in a box in the message header, just like the recipient and the subject.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    San Francisco, California, USA
    Posts
    358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sending an Outlook Email (From) (Office XP)

    As usual, Hans, you are my Savior! My Knight in Shining Armor!!!

    You have no idea how many combinations of replyto's and from's I've tried.... Well, maybe you do *grin*

    Since my text is all in a table and broken up depending on where the next attachment should go, it should be easy enough to count the characters between attachments.

    Thank you so much!

    <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    Update: I can't seem to get the position thing to work properly. It's still attaching at the end of the email. If you have any suggestions, that would be fabulous, but at least the important part is working!

    Here's my code:
    <snip>
    With objOutlookMsg
    .Body = DLookup("EmailText1", "tblEmailData")
    i = Len(.Body)
    Set objOutlookAttach = .Attachments.Add("myfile.mdb")
    objOutlookAttach.Position = i
    End with
    </snip>

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Sending an Outlook Email (From) (Office XP)

    I think the reason you can't get it to work is because your code is putting it at the end - the position i is the length of the body, so it goes after the ith character, or the end. Try setting the attachment position to either 0 or 1 and see if that doesn't make things work like you want.
    Wendell

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    San Francisco, California, USA
    Posts
    358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sending an Outlook Email (From) (Office XP)

    Hey Wendell!

    Sorry for the late reply. It turned out that my problem was that I had my Outlook set for RTF, but was using Word as the editor. Once I had plain old RTF, I was good to go.

    Now if only I can find a setting to programagically turn off Word as my email editor, I'd be set.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •