How to use SmtpNetworkElement for smtp authentication

I am new to programming and visual basic. I am using visual basic 2005. I have looked through other threads on how to do username and password authentication for a smtp server but cannot get any anwers. I have found the class
SmtpNetworkElement which contains properties that could let you use username and password.

Could anyone help me with this class, so that I can send an email from a clients computer, but using my Smtp server

Thank you!

Branodn Smith


Answer this question

How to use SmtpNetworkElement for smtp authentication

  • dws633

    Thank you, Thank you, Thank You!

    This worked perfectly, I just needed to access my smtp server using preset credentials so that any client could send emails from my application. Below is the vb code:

    Imports system.net.mail

    Imports System.Net

    Dim mailClient as New SmtpClient("SmtpHost")

    Dim emailCust as newMailMessage(from, to, subject, message)

    mailclient.deliverymethod = smtpDeliveryMethod.Network

    mailclient.Credentials = New NetworkCredential("SmtpUserName", "SmtpPassword")

    mailclient.send(EmailCust)

     

     



  • haihtomy

    Hey Brandon,

    Are you doing this on your web server or a shared host   I'm trying to figure out how to use SmtpNetworkElement because I need something that opens web.config as read only and can't control the permission in the environment.

    However, if you have your own environment, you can use the following.  FYI, SmtpNetworkElement is just an object to help you pull info from the web.config file.

    If what you are looking for is code to configure and send an email message, you'll need the following:  (Sorry it's in C#)

    MailMessage emailCust = new MailMessage( emailFrom, emailTo, emailSubj, emailBody);
    emailCust.IsBodyHtml = true;
    SmtpClient mailClient = new SmtpClient(mailServer);
    mailClient.DeliveryMethod =
    SmtpDeliveryMethod.Network;
    mailClient.Credentials =
    new NetworkCredential(emailAccName, emailAccPass);

    mailClient.Send(emailCust);

    Of course all the above paramaters in the constructors above are strings that you will need to input your own info.

    If you are looking for a way to store your smtp info in the web.config file, like I said if permissions aren't a problem.  I've gotten the following to work.

    Configuration
    config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
    MailSettingsSectionGroup mailSettings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

    (If you don't know how to setup the SMTP section in the web.config folder, you can research and use the new ASP.Net Configuration utility.  There's a toolbar button to launch it on the top of the Solution Explorer.)

    Hope that helps and if anybody does know how to get

    SmtpNetworkElement smtpNet = new SmtpNetworkElement();
    to get smtp info from the web.config file, I'd appreciate it.

     



  • How to use SmtpNetworkElement for smtp authentication