IndianSage Posted February 24, 2020 Share Posted February 24, 2020 Hi, I am using external VB.net small program which allows me to send email using outside my network. My external code is tested and is working fine from vb.net form. On first step as given in earlier my activity - I am loading vbcode - it gives error: Net.NetworkCredentials not define. I am setting up credentials in side the Dll function called sendEmail with params inputs of credentials, smpt server address etc. During loading step itself this error comes up. Using same this dll creation technique- created other dlls - I called those functions in other dlls from AutoIt script - they works fine. Can anyone help who has tried this out - calling external smtp server to send emails using vb.net. Thanks in advance. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 24, 2020 Moderators Share Posted February 24, 2020 Moved as this is not an AutoIt question. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
IndianSage Posted February 24, 2020 Author Share Posted February 24, 2020 Just would like you to consider again the following observation: This same dll works fine when called from other vb.net program and we are able to send the email however when I call it thru AutoIt wrapper code in DotNetAll.aue3 does not work and give the said error even in loading the code itself. Link to comment Share on other sites More sharing options...
Earthshine Posted February 24, 2020 Share Posted February 24, 2020 why should it surprise you that it works with vb.net when the dll is created in vb.net? and, do you want us to guess at your issues? let me access my 8-ball and ask... My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
IndianSage Posted February 25, 2020 Author Share Posted February 25, 2020 (edited) Below is au3 code: #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <Array.au3> #include <Excel.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StringConstants.au3> #include <WinAPIConv.au3> #include <DotNetAll.au3> ;-------send email using vb src code and Dll sendEmail3() Func sendEmail3() Local $oCode = DotNet_LoadVBcode( FileRead( "Class1.vb" ), "clsSendEmail.dll" ) ; You must add the "System.Windows.Forms.dll" If @error Then Return ConsoleWrite( "DotNet_LoadVBcode ERR" & @CRLF ) ; assembly because of line 1 in the VB code. Exit EndIf ConsoleWrite( "DotNet_LoadVBcode OK" & @CRLF ) ; Exit Local $iRes Local $oClsSendEmail = DotNet_CreateObject( $oCode, "Class1" ) ; $oFoo is an object of the "Foo" class in the VB code If IsObj( $oClsSendEmail ) Then $oClsSendEmail.SendEmail("my email address","my passwrod", "Testing dll with autoit...", "Hi, This is test msg...", "ToEmailAddress", "SMTPServerAddress", "" ,"587", "my email id") ; Test is a method (function) of the $oFoo object Sleep(5000) MsgBox(0,"result","Message sent") EndIf EndFunc Here is the vb.net code: expandcollapse popupImports System.Net.Mail Imports System.Net Public Class Class1 Public myCredentials As Net.NetworkCredential Public Smtp_Server As New SmtpClient Public e_mail As New MailMessage() Public Function SendEmail(ByVal SmtpUserId As String, ByVal SmtpPswd As String, ByVal EmailSubj As String, ByVal EmailBody As String _ , ByVal EmailTo As String, ByVal IpAddr As String, ByVal EmailServer As String, ByVal Port As String, ByVal FromEmailId As String) As Integer ' Dim Smtp_Server As New SmtpClient ' Dim e_mail As New MailMessage() Smtp_Server.UseDefaultCredentials = False Smtp_Server.Credentials = New Net.NetworkCredential(SmtpUserId, SmtpPswd) Smtp_Server.Port = Port Smtp_Server.EnableSsl = True Smtp_Server.Host = IpAddr e_mail = New MailMessage() e_mail.From = New MailAddress(FromEmailId) e_mail.To.Add(EmailTo) e_mail.Subject = EmailSubj e_mail.IsBodyHtml = False e_mail.Body = EmailBody Smtp_Server.Send(e_mail) Return 0 End Function End Class I hope this will help in clarifying the matter. IN case more info is missing please do let me know. Awaiting your reply. Thanks in advance. Edited February 25, 2020 by IndianSage Missing clarification. Link to comment Share on other sites More sharing options...
LarsJ Posted February 25, 2020 Share Posted February 25, 2020 You also need to add references to System.Net and System.Net.Mail. Use this code: Local $oCode = DotNet_LoadVBcode( FileRead( "Class1.vb" ), "System.Net.dll | System.Net.Mail.dll | clsSendEmail.dll" ) IndianSage 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
IndianSage Posted February 27, 2020 Author Share Posted February 27, 2020 I copied both dlls suggested above in the script directory itself from windows folders. It shows following error. BC2017: could not find library 'System.Net.dll ?' How to give multiple dlls? It seems to be syntax, I guess. Link to comment Share on other sites More sharing options...
LarsJ Posted February 27, 2020 Share Posted February 27, 2020 You should not copy System.Net.dll or System.Net.Mail.dll anywhere. They are included in the Global Assembly Cache. You just need to tell the code that it needs these dlls. Use this code to make Net.NetworkCredential work: tst00.au3 #include "DotNetAll.au3" sendEmail3() Func sendEmail3() Local $oCode = DotNet_LoadVBcode( FileRead( "tst00.vb" ), "System.dll | System.Net.dll | netstandard.dll" ) If Not IsObj( $oCode ) Then Return ConsoleWrite( "DotNet_LoadVBcode ERR" & @CRLF ) ConsoleWrite( "DotNet_LoadVBcode OK" & @CRLF ) EndFunc tst00.vb Imports System Imports System.Net Imports netstandard Public Class Class1 Public myCredentials As Net.NetworkCredential End Class Read Microsoft documentation to find out what imports and dlls you need. And just add one or a few lines at a time until you have all the imports and dlls in place and the code works so far. And test code in SciTE so you get all error messages in the console. Earthshine 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
IndianSage Posted February 28, 2020 Author Share Posted February 28, 2020 (edited) THe problem is the following AutoIt code is giving error as mentioned. Let me reiterate: Local $oCode = DotNet_LoadVBcode( FileRead( "tst00.vb" ), "System.dll | System.Net.dll | netstandard.dll" ) Multiple dll mentioned is not working at all with pipe character (|). I get following error on run/exec: BC2017: could not find library 'System.Net.dll ?' Even though the files are there in the @scriptdir - all 3 dlls. Can you give me fix for this issue? Thanks in advance. In parallel, I am trying what you have suggested too and revert with the results. Edited February 28, 2020 by IndianSage To Complete info. Link to comment Share on other sites More sharing options...
IndianSage Posted February 28, 2020 Author Share Posted February 28, 2020 I tried and my code was exactly same what you have proposed. It still gives the error mentioned above. Link to comment Share on other sites More sharing options...
Earthshine Posted February 28, 2020 Share Posted February 28, 2020 (edited) If you can’t find that DLL then you don’t have the right development software installed on your machine. What .net SDk are you using? Edited February 28, 2020 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
LarsJ Posted March 1, 2020 Share Posted March 1, 2020 There have been some problems loading dlls that are not registered in the Global Assembly Cache. Eg. in this and the following posts. It seems like the methods used to load dlls look for them in the wrong directories. You can try specifying the dlls with full path. You can also try copying the dlls to the AutoIt installation directory where AutoIt3.exe and AutoIt3_x64.exe are located. AutoIt3.exe or AutoIt3_x64.exe is the running executable when scripts are run from SciTE. You can analyze the problem with Fuslogvw.exe (Assembly Binding Log Viewer), but it is not quite easy. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now