Pergunta

I have a form sent by email that travels through different persons like this.

Person A --> Person B --> Person C

I want the person A to be informed when the form is treated by person C. So Person A needs to be in copy of the email sent by person B.

Because person A isn't always the same one, I think the best way to put him/her in copy is to use the "from" field of the email received by person B and to put it in copy.

But how can I find this address with infopath and how can I place it into my email data connection ?

Foi útil?

Solução

I had this same question today myself and could not find much in the way of answers.

So... I did some work myself and came up with a few solutions.

First I don't believe there is any way to get/set the "From" address using the InfoPath OM. This means you will have to use one of the following options:

No Code:

You will be limited to providing a field on the form where "Person A" can put their email address and use this in the CC. for subsequent stages. That's kind of the only way and while it an extra burden to the user it does have the benefit of providing flexibility.

Code:

  1. Write your own code to send the mail using Outlook Interop or System.Net.Mail and then you will be setting all of the addresses manually anyway.

  2. If you are using AD or something else then you could always get the email address of the current use using System.DirectoryServices.AccountManagement.

  3. Based on an assumption which I cannot find any documentation to back up. That InfoPath uses the account associated with the default store to send email using EmailSubmitConnection. You should be able to use Outlook Interop to find the address that InfoPath will use.

Here is a code sample:

using Outlook = Microsoft.Office.Interop.Outlook;

public string GetDefaultSenderAddress()
{
    // This actually opens outlook in the same way as InfoPath does to send the message.
    // which can be slow.
    string DefaultAddress = string.Empty;

    Outlook.Application OutlookApplication = new Outlook.Application();
    string DefaultStoreId = OutlookApplication.Session.DefaultStore.StoreID;
    foreach (Outlook.Account Account in OutlookApplication.Session.Accounts)
    {
        if (Account.DeliveryStore.StoreID == DefaultStoreId)
        {
            DefaultAddress = Account.SmtpAddress;
        }
    }
    // Note you probably won't want to quit if you are about to send the email. 
    // However I have noticed that this doesn't seem to close Outlook anyway.
    OutlookApplication.Quit();
    return DefaultAddress;
}

You may have to provide a few more checks in case of different account types etc. But I believe it will work. (I tested it for my scenario and it does).

Note: Of course this opens an outlook instance which you will have to close as well. And it can be slow. Unless outlook is already open in which case it will be very quick. Anyhow when sending from InfoPath Outlook will have to be opened so if you do this just before sending then there should be no noticeable difference.

I would advise using a combination of the no code/with code options so provide a return address which is automatically complete to save the user time. But can be corrected if the user wishes to have the email returned to a different address of if there is a mistake.

Hope that you find that useful.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top