none
visual c# sms gateway RRS feed

  • Question

  • I want to send an email using a c# windows form application.

    Is it possible? If so, what would be the code,

    Tuesday, July 2, 2019 4:45 PM

All replies

  • Your title says SMS, but your message says email.  Those are two very different things.  What are you after?

    The System.Net.Mail.SmtpClient class can be used for simple one-off messages, but anything more sophisticated should use a library like https://github.com/jstedfast/MailKit.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Tuesday, July 2, 2019 6:01 PM
  • Hi,

    >> send an email using a c# windows form application

    To achieve this, here is a simple demo you can refer to. Note that you need to open the "smtp" service first.

        try
        {
            MailMessage message = new MailMessage();
            SmtpClient smtp = new SmtpClient();
    
            message.From = new MailAddress("from@domain.com");
            message.To.Add(new MailAddress("to@domain.com"));
            message.Subject = "Subject";
            message.Body = "Hello World";
    
            smtp.Port = 587;
            smtp.Host = "smtp.domain.com";
            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential("from@domain.com", "password");
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Send(message);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 3, 2019 2:53 AM
  • Hi

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer. So that it will help other members to find the solution quickly if they face the similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 23, 2019 7:42 AM
    Moderator