• Sending an Outlook Email (From) (Office XP)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Sending an Outlook Email (From) (Office XP)

    Author
    Topic
    #403967

    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 , then to bla with this file), 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!

    Viewing 1 reply thread
    Author
    Replies
    • #818145

      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.

      • #818159

        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!

        clapping cheers

        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:

        With objOutlookMsg
        .Body = DLookup(“EmailText1”, “tblEmailData”)
        i = Len(.Body)
        Set objOutlookAttach = .Attachments.Add(“myfile.mdb”)
        objOutlookAttach.Position = i
        End with

        • #819383

          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.

          • #821569

            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.

          • #821570

            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.

        • #819384

          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.

      • #818160

        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!

        clapping cheers

        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:

        With objOutlookMsg
        .Body = DLookup(“EmailText1”, “tblEmailData”)
        i = Len(.Body)
        Set objOutlookAttach = .Attachments.Add(“myfile.mdb”)
        objOutlookAttach.Position = i
        End with

    • #818146

      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.

    Viewing 1 reply thread
    Reply To: Sending an Outlook Email (From) (Office XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: