Get windows default mail client's smtp details in to C# code

188 views Asked by At

I' am developing simple windows form application using C#. in this case I need to send email using this application. And in this time I already configured Mozilla Thunderbird as default mail client. My code requires default mail client smtp host and credentials. therefore I need to get these things from windows default mail client.

My Code:

    MailMessage mail = new MailMessage();

    //set the addresses
    mail.From = new MailAddress("[email protected]");
    mail.To.Add("[email protected]");

    //set the content
    mail.Subject = "sampleSubject";
    mail.Body = "sampleBody";

    //add an attachment from the filesystem
    mail.Attachments.Add(new Attachment(filePath));

    //send the message
    SmtpClient smtp = new SmtpClient("smtpHOst");
    smtp.Credentials = new NetworkCredential("username", "password");
    smtp.Send(mail);
0

There are 0 answers