0

Can any one tell me if there is a way to select a specific profile without using mapi.

So far my code looks as shown below:

Outlook.Application app = null;
if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
{
   app = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
}
else
{
   app = new Outlook.Application();    
}
            
Outlook.MailItem mymail = app.CreateItem(Outlook.OlItemType.olMailItem);
mymail.Subject = aSubject;
for (int i = 0; i < (int)atargets.Count(); ++i) mymail.Recipients.Add(atargets[i]);
for (int i = 0; i < (int)aAttach.Count(); ++i) mymail.Attachments.Add(aAttach[i]);
mymail.Body = aBody;
mymail.Importance = Outlook.OlImportance.olImportanceHigh;
mymail.Display(false);
return true;
Chris Catignani
  • 5,040
  • 16
  • 42
  • 49
  • Can you explain `without MAPI`? or is this what you are looking for: 1) https://learn.microsoft.com/en-us/office/client-developer/outlook/pia/how-do-i-outlook-2013-pia-reference 2) https://learn.microsoft.com/en-us/office/client-developer/outlook/pia/how-to-send-a-mail-item-by-using-a-hotmail-account – Luuk Feb 10 '20 at 14:05
  • the problem with mapi is i can use it to communicate between x32 APP and x64 outlook. so i need to find a way to select user to send.ive read through both of ur articles before. they would work if i didnt want to open mail and be able to edit text or something cause they send it with "mail.Send()", i want to giv the user the option to edit hismail before sending so i just create it and show it. pressing the send button auto puts the mail into standard profiles outbox even tho im "loggedin" with lets say profile x – Roman Kreuzer Feb 10 '20 at 14:12
  • When you say 'profiles', do you mean the ones you see in 'Mail', 'Profiles' in Control Panel? Outlook runs in the context of a single profile, so I doubt you can without restarting Outlook. If you're saying that it picks a different profile for automation then I'm surprised, since you're attaching to an existing process by the look of it rather than starting a new one for automation :-/ – Rup Feb 10 '20 at 14:28
  • https://www.amazon.com/Programming-Microsoft-Office-Current-Service/dp/1509300910 Perhaps see if you can find the guy who wrote this books blog - or perhaps do a Google book search to see if you can get to grips off the snippets within, – JGFMK Feb 10 '20 at 14:29
  • IIRC they do it via Azure in that book. There are probably a whole host of ways. – JGFMK Feb 10 '20 at 14:30
  • This will show you how to get the different addresses configured for the current user: https://stackoverflow.com/questions/18606088/get-outlook-email-address-through-c-sharp – Luuk Feb 10 '20 at 15:18
  • What's the actual requirement (beware of the XY problem). Is the goal is to send an email with some attachements and a computer body, maybe you should consider directly send to a SMTP server. In opposition, if you want to prepare the email for the user, keeping a window where the user can control or edit the message, it's OK. Maybe you should take a look at https://github.com/PandaWood/Simple-MAPI.NET – Steve B Feb 10 '20 at 17:15

0 Answers0