How to get current login user - outlook

I want to get current login user via EWS. I search some document, but I don’t find a method to get current user. I need your help. Thanks very much

Use ResolveName EWS operation - you will only need the user's SMTP address.

As Dmitry said, you could use ResolveName. For example:
NameResolutionCollection ncCol = service.ResolveName("user#domain.com",ResolveNameSearchLocation.DirectoryOnly,true);
Console.WriteLine(ncCol[0].Contact.DisplayName);
You could also use ConverId with a generic address to get the current user’s own email. For example:
Folder Inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
AlternateId aiAlternateid = new AlternateId(IdFormat.EwsId, Inbox.Id.UniqueId, "mailbox#domain.com");
AlternateIdBase aiResponse = service.ConvertId(aiAlternateid, IdFormat.EwsId);
Console.WriteLine(((AlternateId)aiResponse).Mailbox);
AutoDiscover will also return the PrimarySMTP address of a Mailbox as you do a POX based discovery.

Related

How to get smtp address of current Outlook store

We have user with 3-4 shared email address in Outlook.
I am developing add-in where it will extract the email address of selected store and will get it's contact folder from People.
My problem is I don't know how to get email address of SelectedStore.
Here is my code.
string recipientName = SelectedStore.EmailAddress; // This is what I want to make it work
Outlook.Recipient recip = ns.CreateRecipient(recipientName);
recip.Resolve();
if (recip.Resolved)
{
Outlook.MAPIFolder folderContacts = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderContacts);
}
Any help will be appreciated.
Thank you.
For the mailbox owner, you can either try to read the MAPIFolder.Store property to get to the parent store, then read the PR_MAILBOX_OWNER_ENTRYID property (DASL name "http://schemas.microsoft.com/mapi/proptag/0x661B0102") using Store.PropertyAccessor.GetProperty. You can then use the store owner entry id to call Namespace.GetAddressEntryFromID. Once you have the AddressEntry object, you can use AddressEntry.GetExchangeUser.PrimarySmtpAddress.
Note that PR_MAILBOX_OWNER_ENTRYID property is only available in the online stores. You might want to use Redemption (I am its author) and its RDOExchangeMailboxStore.Owner.SmtpAddress property. RDOExchangeMailboxStore can be retrieved using RDOSession.GetRDOObjectfromOutlookObject(Store) or using RDOSession.GetStoreFromID.
You can also try to retrieve the store entry id and parse it - its format is documented and you can extract the EX type address of the owner. You can then construct the GAL entry id to open the AddressEntry object. From there, you can retrieve the SMTP address.
Just to let you know, I found the solution.
Outlook.MAPIFolder folderContacts = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
should do the trick.

Thunderbird - Get the user email address

I am developing a Mozilla Thunderbird plug-in and need to get the user's email address.
Question: How do I retrieve this address?
I will use it inside a JavaScript.
You should first keep in mind that a user can have multiple e-mail addresses (from multiple accounts or even multiple identities for one account), and you have to decide in which one you are interested.
Note: there may exist an easier way then described below, e.g. a helper function in the existing Thunderbird Code. You could try to search comm-central for it
You somehow have to get the nsIMsgIdentity for the identity you are interested in. It has an email property, with the e-mail adress as a string.
One way to get all Identities should be via the allIdentities of nsIMsgAccountManager (didn't test it).
Use the follwing code to get the nsIMsgAccountManager:
Components.utils.import("resource:///modules/mailServices.js");
let accountManager = MailServices.accounts
If you have an nsIArray of nsIMsgIdentity, you can use the following code to loop over them:
for (let identity in fixIterator(identities, Components.interfaces.nsIMsgIdentity)) {
}
References which could be useful:
Overview of some interesting interfaces:
https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Account_interfaces
Some account example Code:
https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Account_examples

Is it possible to send emails programmatically to a PHPList list?

I am looking for a solution to send automated emails from my website to PHPList lists. From my understanding, PHPList's emails are authored manually using the web-based interface provided by the application. Are there some APIs I can use to allow my website to send emails directly?
You can just code one like this, just need to change some of the values on the insert strings to match your list. So when someone creates and account on your website, you just call a routine like this and insert it into PHPLIST.
You can also do it with a trigger on your members table. The code below is VB.NET - but you can easily convert it to php.
Public Sub AddMemberToPHPList(ByVal vUserEmail As String)
Dim moConn As MySqlConnection
moConn = New MySqlConnection("server=*********;User Id=******;Password=*******;Persist Security Info=True;database=phplist;Ssl Mode=None;Allow User Variables=True;")
moConn.Open()
Dim oMySqlCommand As New MySqlCommand
oMySqlCommand.Connection = moConn
oMySqlCommand.Parameters.AddWithValue("email_address", vUserEmail.ToLower)
oMySqlCommand.Parameters.AddWithValue("uniqid", Guid.NewGuid)
oMySqlCommand.CommandText = "INSERT IGNORE INTO phplist_user_user set email = ?email_address, confirmed=1,entered = now(),modified = now(),uniqid = ?uniqid,htmlemail = 1, bouncecount=0,disabled = 0"
oMySqlCommand.CommandType = CommandType.Text
oMySqlCommand.ExecuteNonQuery()
oMySqlCommand.CommandText = "INSERT IGNORE INTO phplist_listuser set userid = (select id from phplist_user_user where email = ?email_address) , listid = 3, entered = now(), modified= now()"
oMySqlCommand.ExecuteNonQuery()
End Sub
first, if is a list of emails, yo need use queues, you only need have the emails stored in a database, and then sending through queues with a cicle of the emails of the database
This reply is rather late I realize, but I think you'd do well to look into this plugin for PHPList:
https://resources.phplist.com/plugin/submitbymail
The plugin page says that the author is no longer supporting/developing the plugin, but the code that is there should work on current versions of PHPList.
I used to use an older plugin (called 'MailToList') for this exact purpose - someone can compose an email somewhere else, send it to a specific address on their system, and then the plugin watches those email inboxes for new emails and will queue up a new 'campaign' using that email as the source. So you essentially have to set up one email inbox for each list you want to send out to in PHPList.
(I'm just going through an upgrade process on my PHPList system and will probably use this 'SubmitByMail' plugin since the 'MailToList' plugin appears to not exist any more. But I haven't yet actually used the 'SubmitByMail' plugin.)

How to get user details (job, title, department, location etc) using outlook EWS using his AD login ID

I need to get certain details for a user by his AD login ID.
Remember I just don't want to look into that user's contacts only. I want to look in global list and find the details (Similar details is shown when you double click the name of the person in the email message from, to, cc )
I found lot of links out there but they don't show any example for global search of user.
I tried to do something similar shown in this link
http://msdn.microsoft.com/en-us/library/jj220498(v=exchg.80).aspx
however it just within my own contacts.
Can anybody show a simple example or link for the same?
I found that ResolveName method does the trick. I can query by user's full name. I am just posting a method. I assume 'service' is already instantiated using proper domain/url/credentials
public Contact GetContactInfo(string sFullName)
{
Contact contact = null;
try
{
NameResolutionCollection allContacts = service.ResolveName(sFullName, ResolveNameSearchLocation.DirectoryOnly, true);
if (allContacts.Any())
{
contact = allContacts[0].Contact;
}
}
catch (Exception ex)
{
LogHelper.Error("Error in GetContactInfo(): ", ex);
//throw;
}
return contact;
}
Have you tried the ResolveName method?
http://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.exchangeservice.resolvename%28v=exchg.80%29.aspx
You can search the contacts folder and/or global address list with it. Make sure you set the boolean value to return the Contact with it.
I was looking for user's details and GetPersona is the operation.
Sharing with the concern that it may help others who are digging google & Microsoft to get user's information.
GetPersona operation
The GetPersona operation returns a set of properties that are associated with a persona.

netusergetinfo return 2221

netusergetinfo is returning 2221 error code for valid user . What is the reason? It is because of some security setting on active directory but I am not aware of it.
Probably you have the same problem as described here Get current user's last logon.
One possible reason is that you don't use UNICODE format for the user name.
Another problem is if you try to ask the name of domain user. In this case you should use not a form
nStatus = NetUserGetInfo (NULL, L"Domain\\TestUser", dwLevel, (LPBYTE *) & pBuf);
but use as the first parameter the name of a domain controller from a domain which has trust to domain "Domain". You can use DsGetDcName or NetGetAnyDCName or NetGetDCName to get this name.
To answer on your question exactly you should post the corresponding source code and describe shortly your domain environment and the role of the computer and the current user under which current process are running.
API: NetUserSetInfo / netusergetinfo
Error Code: 2221
Reason: The Username you are trying to update is not present in the system.
for reference:https://learn.microsoft.com/en-us/windows/win32/netmgmt/network-management-error-codes

Resources