none
.NET System.net.mail and authentication RRS feed

  • Question

  • I work in a manufacturing environment so most of my scripting experience is in proprietary languages. However, the software that I'm currently using (Archestra System Platform) allows for .NET scripting

    I found some sample code for System.Net.Mail.  I set upSmtpClient.Host, .Port and .EnableSSL = true.  I made registry edits to EnableSSL per other stuff that I googled.

    This on a W2008R2 server in a development environment.  I'm using smtp.gmail.com, port 465 (which I can ping from the hosting server)

    But I don't understand how/where to enter my gmail account credentials?

    I had enabled and configured IIS on the server.  And saw that I could put my gmail credentials in there but that didn't seem to work either.

    The error that I'm getting says "failure sending mail".  Everything that I read about that error indicated that it was something with the connection to the SMTP server.

    This is not my regular programming environment so I'm hoping it's something simple that I just am clueless about.

    'Declare local variables
    Dim objSMTPClient as System.Net.Mail.SmtpClient;
    Dim objMessage as System.Net.Mail.MailMessage;
    Dim strFrom as String;
    Dim strRecipients as String;
    Dim strSubject as string;
    Dim strBody as string;
    
    'Set up basic SMTP configuration
    objSMTPClient = New System.Net.Mail.SmtpClient;
    objSMTPClient.Host = "smtp.gmail.com";
    objSMTPClient.Port = 465;
    objSMTPClient.UseDefaultCredentials = true;
    objSMTPClient.EnableSsl = true;
    
    'Set the to & from
    strFrom = me.Mail.From;
    strRecipients = me.Mail.Recipients;
    objMessage = New System.Net.Mail.MailMessage (strFrom,strRecipients);
    
    'Build up a subject line
    strSubject = me.Mail.Subject + ">> "+ Now() + " <<" + Me.Area;
    objMessage.Subject = strSubject;
    
    'Fill out the body of the email
    strBody = me.Mail.Body + objSMTPClient.Host + " " + objSMTPClient.Port;
    objMessage.Body = strBody;
    objMessage.IsBodyHTML = False;
    
    if me.Mail.Debug then
    	LogMessage("SMTP server & port: " + objSMTPClient.Host + " " + objSMTPClient.Port.ToString());
    	LogMessage("To: " + strFrom + " - Recipients: " + strRecipients);
    	LogMessage("Subject : " + strSubject);
    	LogMessage("Body : " + strBody);
    endif;
    
    'Send the finished message
    objSMTPClient.Send(objMessage);



    • Edited by Kirkee Tuesday, August 15, 2017 3:56 PM
    Tuesday, August 15, 2017 3:54 PM

Answers

  • Sorry but this is not a VB forum and you are trying to use VB code.  Post you issues in a VB forum.  VB is not a scripting language.

    Also note that this forum does not fix code found on the Internet.  You might also try to post to the author of the code for help.


    \_(ツ)_/

    • Marked as answer by Kirkee Tuesday, August 15, 2017 6:47 PM
    Tuesday, August 15, 2017 5:00 PM

All replies

  • Sorry but this is not a VB forum and you are trying to use VB code.  Post you issues in a VB forum.  VB is not a scripting language.

    Also note that this forum does not fix code found on the Internet.  You might also try to post to the author of the code for help.


    \_(ツ)_/

    • Marked as answer by Kirkee Tuesday, August 15, 2017 6:47 PM
    Tuesday, August 15, 2017 5:00 PM
  • Was asking for help to understand dependence between .Net (which I thought was a scripting language) and IIS.  I will post elsewhere.
    Tuesday, August 15, 2017 6:25 PM
  • .Net is not a scripting language,  It is an API framework.  The code posted is VB.Net which is not a scripting language.

    For IIS issues post here: http://forums.iis.net


    \_(ツ)_/

    Tuesday, August 15, 2017 6:28 PM