Avatar of me24hour
me24hour
Flag for United States of America asked on

how to send 2 emails on infopath submit button

Hi,

When the user hits submit button, I want to send two emails having two different bodies to 2 different users.
I think it can be possible only using custom code.
So, please put me in the right direction
Microsoft Server AppsInfoPathMicrosoft SharePoint

Avatar of undefined
Last Comment
me24hour

8/22/2022 - Mon
Clay Fox

A couple possible methods.

One question is are you going to send the form as an attachment or send a view?

You can create 2 email submit data connections

In the past i have switched to a specific view for email and then switched back.

Not sure if you could do this twice to get the 2 html bodies you want.  I would think by code you could make this happen and the user would only see a bit of flickering.
me24hour

ASKER
I want to send the form as a view.
And, actually just for testing i have writtent the following code.
using System.Net.Mail;
public void CTRL28_5_Clicked(object sender, ClickedEventArgs e)
        {
            // Write your code here.
            MailAddress toAddress = new MailAddress("abcd@gmail.com");
            MailAddress fromAddress = new MailAddress("ghtk@gmail.com");

            using (MailMessage msg = new MailMessage(fromAddress, toAddress))
             {
               msg.Subject = "New subject";
               msg.Body = "Hello";
               SmtpClient smtp = new SmtpClient("smtp.gmail.com");
               smtp.EnableSsl = true;
               smtp.Send(msg);
 }
        }

Open in new window

But when i try to debug it get a runtime error at smtp.Send(msg);
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. "
Clay Fox

I would not get that complicated. And would try it with the email submit data connections.

I guess you are trying to make it completely invisible to the user, but not sure how you will do that unless you body will be text rather than the view.

It looks like your smtp is not conifugred correctly, either with the right server or the right authentication.  I would test that first.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
me24hour

ASKER
i started trying with email submit data connections
can i hook up two different email data connections with the same submit button.
but i want to send two different emails to two different users with different messages.
ASKER CERTIFIED SOLUTION
Clay Fox

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
me24hour

ASKER
thanks for your input...it is very helpful.
the only issue i am facing now is that outbound SMTP server is not setup.
what should i put in here in SP ?
Outbound SMTP server: