Rob Maiman

Rob Maiman

  • NA
  • 7
  • 528

send email via 3rd party SMTP - authentication protocols

Sep 22 2022 6:45 PM

plenty of examples using  show the syntax which is easy. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Net.Mail;
using System.Net;

namespace MyRND_in_WPF
{
    /// <summary>
    /// Interaction logic for SendMail.xaml
    /// </summary>
    public partial class SendMail : Window
    {
        public SendMail()
        {
            InitializeComponent();
        }

        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            //created object of SmtpClient details and provides server details
            SmtpClient MyServer = new SmtpClient();
            MyServer.Host = "";
            MyServer.Port = 81;

            //Server Credentials
            NetworkCredential NC=new NetworkCredential();
            NC.UserName="";
            NC.Password="";
            //assigned credetial details to server
            MyServer.Credentials = NC;

            //create sender address
            MailAddress from = new MailAddress("Sender Address", "Name want to display");

            //create receiver address
            MailAddress receiver = new MailAddress(txtToAddress.Text.Trim(), "Name want to display");

            MailMessage Mymessage = new MailMessage(from, receiver);
            Mymessage.Subject = txtSubject.Text.Trim();
            Mymessage.Body = txtDocument.Text.Trim();
            //sends the email
            MyServer.Send(Mymessage);
        }
    }
}

 

Yet very few if any examples discuss how to handle the various protocol limits places by 3rd party email providers.

eg, google uses app login, yahoo supposedly does same but dont' support the app pw as of trying this morning, some like gmx.com use TLS  etc.

in the example above uses the NetworkCredential class which doesn't have properties like SSL or TLS