locked
Email using button

    Question

  • Hello,

    I have been building an Email application, Somehow i have succeeded in sending an email through SMTP client to the recipient. But now how can i send the email when the user enters his details in the textboxes in my application. Looking forward for the source code.

    Thanks & Regards

    Manideep Mummadi


    manideep

    Friday, September 05, 2014 11:38 AM

Answers

  • Christian's suggestion is specific for Windows Phone Runtime apps. Mohammed's suggestion is specific to Windows Phone Silverlight apps.

    This thread is in the Windows Store app development forum.

    There is no explicit email API for Windows Store apps. Depending on the specific needs you can use the share charm (best for general purpose sharing since the user can choose how and where to share), launch a mailto: link (to let the user add their own text to send to a specific address. I generally don't recommend this: its easy, but not a great user experience), or bypass email and talk to a dedicated web service (generally the best for feedback forms as such).

    For the specific case of an email app you'll need to set up your own connection to the email server and talk SMTP, POP, etc. There isn't an inbox API for this so you'll need to use HttpClient or the socket API.

    Sunday, September 07, 2014 4:06 PM
    Owner

All replies

  • Hi,

    You can perform it like that :

    Xaml :

     <TextBox x:Name="Recipient" HorizontalAlignment="Left" Margin="113,167,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="212" Text="Recipient :" InputScope="EmailSmtpAddress"/>
            <TextBox x:Name="Subject" HorizontalAlignment="Left" Margin="113,247,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="212" Text="Subject :"/>
            <TextBox x:Name="Body" HorizontalAlignment="Left" Margin="113,319,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="212" Text="Body " Height="124"/>
            <Button Content="Send Email" HorizontalAlignment="Left" Margin="148,478,0,0" VerticalAlignment="Top" Click="SendEmail"/>
    

    Code behind :

     async void SendEmail(object sender, RoutedEventArgs e)
            {
                EmailRecipient sendTo = new EmailRecipient()
                {
                    Address = Recipient.Text
                };
               
                //generate mail object
                EmailMessage mail = new EmailMessage();
                mail.Subject = Subject.Text;
    
                //mail body
                mail.Body = Body.Text;
    
                //add recipients to the mail object
                mail.To.Add(sendTo);
                //mail.Bcc.Add(sendTo);
                //mail.CC.Add(sendTo);
    
                //open the share contract with Mail only:
                await EmailManager.ShowComposeNewEmailAsync(mail);
            }


    Don't forget to add the following directive :

    using Windows.ApplicationModel.Email;

    Cheers,
    Christian H.


    The best is still to come ;)

    Friday, September 05, 2014 5:02 PM
  • When i am trying the directive, the class is not present in the application model. 

    i am including a screenshot of the error i am getting when i am  trying to add the directive email to the CS file. Please tell me how to get the email as my directive in the CS file.


    manideep

    Sunday, September 07, 2014 8:05 AM
  • Use EmailComposeTask.

    void SendEmail (object sender , RoutedEventsArgs e)
    
    {
    
    EmailComposeTask emailComposeTask = new EmailComposeTask();
    
    emailComposeTask.To = "your email id@whatever.com";
    
    emailComposeTask.Subject = "Subject of Email";
    
    emailComposeTask.Body = "";
    
    emailComposeTask.Show();
    
    }

    This is a really simple way and this will help you.

    If found Helpful mark as answer.

    Muhammad Asad


    Sunday, September 07, 2014 10:52 AM
  • Christian's suggestion is specific for Windows Phone Runtime apps. Mohammed's suggestion is specific to Windows Phone Silverlight apps.

    This thread is in the Windows Store app development forum.

    There is no explicit email API for Windows Store apps. Depending on the specific needs you can use the share charm (best for general purpose sharing since the user can choose how and where to share), launch a mailto: link (to let the user add their own text to send to a specific address. I generally don't recommend this: its easy, but not a great user experience), or bypass email and talk to a dedicated web service (generally the best for feedback forms as such).

    For the specific case of an email app you'll need to set up your own connection to the email server and talk SMTP, POP, etc. There isn't an inbox API for this so you'll need to use HttpClient or the socket API.

    Sunday, September 07, 2014 4:06 PM
    Owner