Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Emails mit Windows App versenden. uwp

19.07.2018 (๐Ÿ‘7692)

UWP Email senden direkt รผber SMTP

Dieses Code Beispiel zeigt, wie man in UWP Windows App einen Email direkt aus der App versendet.

UWP Beispiel Code

Windows App

C# Code zum einbinden.

            //------------< send_Email() >------------

            //send email with uwp and smtp-server

            //< email >

            MailMessage email = new MailMessage();

            email.To.Add("Test@Readdy.Net");

            email.From= new MailAddress("service@readdy.net""Email-Server");

            email.Subject = sTitle;

            email.Body = sText;

            //</ email >

 

            //< email-server >

            SmtpClient client = new SmtpClient();

            client.Host = app_settings._Smtp_Server;

            client.UseDefaultCredentials = false;

            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            //< no ssl >

            client.Port = 25;

            client.EnableSsl = false;

            //</ no ssl >

            client.Credentials = new NetworkCredential("postmaster@readdy.net""0123456789");

            //</ email-server >

 

            //< send >

            client.Send(email);                       //*with error message

            //</ send >

 

 

 

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using System.Threading.Tasks;           //*async

using System.Net.Mail;                  //*smtp client

using System.Net;                       //*Network Credential

//using Windows.ApplicationModel.Email;   //*email with default app

 

 

namespace test_app02_server

{

    /// <summary>

    /// * send an email with uwp direct over smtp account

    /// </summary>

    public sealed partial class MainPage : Page

    {

        public MainPage()

        {

            this.InitializeComponent();

        }

 

        private async void BtnSend_Email_Click(object sender, RoutedEventArgs e)

        {

            await send_Email("UWP Email Test""this is a email from uwp app");

        }

 

 

        public static async Task<bool> send_Email(string sTitle, string sText)

        {

            //------------< send_Email() >------------

            //send email with uwp and smtp-server

            //< email >

            MailMessage email = new MailMessage();

            email.To.Add(app_settings._admin_Email);

            email.From= new MailAddress(app_settings._Smtp_User, "Email-Server");

            email.Subject = sTitle;

            email.Body = sText;

            //</ email >

 

            //< email-server >

            SmtpClient client = new SmtpClient();

            client.Host = app_settings._Smtp_Server;

            client.UseDefaultCredentials = false;

            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            //< no ssl >

            client.Port = 25;

            client.EnableSsl = false;

            //</ no ssl >

 

            //< ssl >

            //*securesmpt.t-online.de

            //client.Port = 587;

            //client.EnableSsl = true;

            //</ ssl >

            client.Credentials = new NetworkCredential(app_settings._Smtp_User, app_settings._Smtp_Password);

            //</ email-server >

 

            //< send >

            //await client.SendMailAsync(email);      //*no error message

            client.Send(email);                       //*with error message

            //</ send >

 

            return true;

            //------------</ send_Email() >------------

        }

 

 

    }

}

Dann kommt die Email wie hier an