Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Mail 397 - using Newmessage but being able to select a user profile

(0) ShareShare
ReportReport
Posted on by 5,136

I am using Mail codenuit (397)'s newmessage function to be able to create a new Outlook Message and have users review the message before sending.  This is working well and good.  However, I want to be able to automatically select a user profile as the sender.  Can I do this programmatically?  E.g., in my Outlook, I actually have two user profiles.  I want my recipients to know that email came from a specific email address.  if I can hardcode this in Nav, it's okay too.  Please advise.

*This post is locked for comments

  • Alais Profile Picture
    20 on at
    RE: Mail 397 - using Newmessage but being able to select a user profile

    Hi!

    Im using this method, but I have a problem:

    My customer use the application from more than one NAV sessions, and then there is a conflict:

    "changes made to the item were lost because of a reconnect with the server"

    I need reset or close the app instance between calls, but I dont know how to do it.

    It's possible?

    Thanks!

  • Community Member Profile Picture
    on at
    RE: Mail 397 - using Newmessage but being able to select a user profile

    Help!

    Mail.NewMessage function is working perfectly fine and on click it opens the email in the outlook and this is what I want. But there's a problem in it. If the Outlook app is closed then it opens the dialog box and on the click, email can be sent easily but if the outlook is already opened, it doesn't happen. 

    What to do in case when Outlook is already opened?

  • mbr Profile Picture
    5,136 on at
    RE: Mail 397 - using Newmessage but being able to select a user profile

    'glad I could help! :)

  • jgaztanaga Profile Picture
    225 on at
    RE: Mail 397 - using Newmessage but being able to select a user profile

    Dear mbr. It was that, exactly!. runonclient property was set on No and once I have changed everything works fine. Thanks a lot for your help! It was great, indeed

  • mbr Profile Picture
    5,136 on at
    RE: Mail 397 - using Newmessage but being able to select a user profile

    Did you change the runonclient property of your .Net variables to YES?  E.g., go to your global or local variable where you have OutlookMessageHelper declared and press shift-F4.  There's a Runonclient property that you want t set to YES.  Also, I am assuming you have all the necessary ms office integration dlls installed in your addins folder.

  • jgaztanaga Profile Picture
    225 on at
    RE: Mail 397 - using Newmessage but being able to select a user profile

    mbr, first of all thanks a lot for your help. I must be doing something wrong. I have create a new method: CreatenewMessage2, coping the code you wrote, and when I call that method from a NAV2013 page I receive this error: "An instance of the .NET Framework object: assembly Microsoft.Office.Interop.Outlook, version=15.0.0.0 ......  cannot be created"

  • Suggested answer
    mbr Profile Picture
    5,136 on at
    RE: Mail 397 - using Newmessage but being able to select a user profile

    Below code is for use to use the Clientside implementation of OUtlook New message.  Nav Version is 2013.  It's also sending message as HTML.

    Declaration:

    Name DataType Subtype Length

    olApp DotNet Microsoft.Office.Interop.Outlook.ApplicationClass.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    olMailItem DotNet Microsoft.Office.Interop.Outlook.MailItem.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    olItemType DotNet Microsoft.Office.Interop.Outlook.OlItemType.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    olAccountList DotNet Microsoft.Office.Interop.Outlook.Accounts.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    olAccount DotNet Microsoft.Office.Interop.Outlook.Account.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    olAttachmentType DotNet Microsoft.Office.Interop.Outlook.OlAttachmentType.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    OutlookMessageHelper DotNet Microsoft.Dynamics.Nav.Integration.Office.Outlook.IOutlookMessage.'Microsoft.Dynamics.Nav.Integration.Office, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

    CreatenewMessage Method

    senderMailAddress := DefaultEmailSender;

    olApp := olApp.ApplicationClass();

    olItemType := olItemType.olMailItem;

    olMailItem := olApp.CreateItem(olItemType);

    //find the selected outlook profile and set it as sender mail address

    olAccountList := olApp.Session.Accounts;

    idx :=1;

    REPEAT

     olAccount := olAccountList.Item(idx);

     IF LOWERCASE(olAccount.SmtpAddress) = LOWERCASE(senderMailAddress) THEN

       olMailItem.SendUsingAccount := olAccount;

     idx += 1;

    UNTIL idx > olAccountList.Count;

    olMailItem.Subject := Subject;

    olMailItem."To" := TORecipients;

    olMailItem.CC := CCRecipients;

    olMailItem.BCC := BCCRecipients;

    olMailItem.HTMLBody := '<HTML><BODY>' + BODY + '</BODY></HTML>';       //We want to send in HTML format

    olMailItem.BodyFormat := 2;

    IF BackOrdered THEN BEGIN

     fileName := FileAttachment;

     olMailItem.Attachments.Add(fileName,olAttachmentType.olByValue,1,fileName)

    END;

    olMailItem.Display(ShowDialog);

    ----above method will actually pop up the OUtlook Message...so user can choose to edit the message before sending.  It also has file attachment.

    Let me know if you have further questions.

  • jgaztanaga Profile Picture
    225 on at
    RE: Mail 397 - using Newmessage but being able to select a user profile

    I did not mbr... I created the dotnet variable and a new function based on what Jonathan sugested but I am not able to make it run. I really would appreciate your help

  • mbr Profile Picture
    5,136 on at
    RE: Mail 397 - using Newmessage but being able to select a user profile

    did you get your mail and .net interop to work?

  • mmv Profile Picture
    11,467 on at
    RE: Mail 397 - using Newmessage but being able to select a user profile

    Hi,

    If the standard function is not suiting your requirement, you may create another one.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics NAV (Archived)

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans