Link to home
Start Free TrialLog in
Avatar of me24hour
me24hourFlag 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
Avatar of Clay Fox
Clay Fox
Flag of United States of America image

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.
Avatar of 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. "
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.
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
Avatar of Clay Fox
Clay Fox
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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: