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

Send emails with WPF

17.08.2018 (👁241)


 

With the following code sample you can easily send emails in WPF applications

 

 

Please adjust or change variables in the code:

 

To do this you have to set variables or swap them in the C # code

app_settings._Smtp_User 

app_settings._smtp_password

 

the call parameters:

string sTitle, string sText

 

the receiver

app_settings._admin_email

 

and the visible sender

app_settings._Smtp_User, "Search Agent"

 

Code Sample: send emails

using System;

 

using System.Threading.Tasks;           //*async

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

using System.Net;                       //*Network Credential

//using Windows.ApplicationModel.Email;   //*email

 

public static class clsEmail

{

    //============< clsEmail >============

    public static 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, "Searchagent");

        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() >------------

    }

    //============</ clsEmail >============

}