I thought this would be a simple task but found I was very wrong apparently. We have a working application that resides in a Windows Server 2016 system This app needs to be triggered remotely by a general user who clicks on a shortcut pointed to the .exe on the server. The problem is that the app needs to be able to run using the server's resources so that an email can be sent (only servers are capable of sending emails).
It seems that the app runs with the user's resources so the email never gets sent. I'm not sure if I need to add some type of scripting (VB.Net) or if I need to configure the .exe/server to enable this function. This works when a user with Admin rights runs the app but we need a regular User to be able to do the same. I have tried using PsExec but still had the same problem. (The user is using Windows 10)
Does anyone have any ideas that can make this happen?
This is the code we're using for the mail function:
Dim client As New SmtpClient()
Dim mail As New MailMessage()
mail.From = New MailAddress("email#email.com")
client.Credentials = New Net.NetworkCredential("username", "password")
mail.[To].Add("email#email.com")
mail.[To].Add("email#email.com")
'set the content
mail.Subject = "Subject: " & Date.Now
mail.Body = "Body: " & Date.Now
client.Host = "host.host.host.com"
client.Port = "25"
client.UseDefaultCredentials = True
Try
client.Send(mail)
Catch exc As Exception
Finally
mail = Nothing
client = Nothing
End Try
Catch ex As Exception
' MsgBox("Error, DB Open " & ex.Message)
End Try
Related
I usually send email using a full-featured library (Chilkat) but I want to try to compose the email manually to examine differences. I'm using this for starters:
Imports System.Net.Mail
Dim mail As New MailMessage()
mail.From = New MailAddress("MyMail#Gmail.com")
mail.To.Add("MyMail#yahoo.com")
mail.Subject = "Test1 "
mail.IsBodyHtml = False
mail.Body = "This is a test."
Dim smtpServer As New SmtpClient
smtpServer.Credentials = New Net.NetworkCredential("MyMail#Gmail.com", "MyMailPWD")
smtpServer.Port = 465
smtpServer.Host = "smtp.gmail.com"
smtpServer.EnableSsl = True
smtpServer.Timeout = 3000
smtpServer.Send(mail)
MsgBox("The mail Is sent!", MsgBoxStyle.Information)
But I keep getting a timeout error on the Send command. The credentials are all good because it works fine using Chilkat. I also know that I am reaching smtp.gmail.com because it's not happy if I switch to port 587. How can I get a detailed report of the exchange for debugging purposes? Thanks.
Gmail no longer allows basic SMTP access by default. It used to be you could get around this by enabling a "Less Secure Apps" option, but now this is gone, too, or soon will be (certain types of accounts are phasing this out more slowly, but it IS going away).
Instead, you have to use a modern authentication mechanism like OAuth, or create a per-App password.
Windows Forms application using VB.Net and VS2012. Connecting to an Access database using Access Runtime 2013. The app is compiled to target x86. The problem is intermittent and occurs on multiple different PC's randomly, and accessing a database on a local hard drive.
Using cn As New OleDbConnection
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
If Not OpenDBConnection(cn) Then
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
MsgBox("Unable to make database connection to update screen status.", MsgBoxStyle.OkOnly, "Database Connection Error (MMUN1)")
Exit Sub
End If
'continue processing....
end using
Public Function OpenAccessConnection(ByRef conn As OleDb.OleDbConnection) As Boolean
Dim builder As New OleDbConnectionStringBuilder()
'conn.Provider = "Microsoft.ACE.OLEDB.12.0"
Try
builder.ConnectionString = "Data Source=" & DPATH & DBNAME
builder.Add("Provider", "Microsoft.ACE.OLEDB." & ACCESSVER & ".0") 'ACCESSVER is '12'
conn.ConnectionString = builder.ConnectionString
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
conn.Open()
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
Return True
Catch ex As Exception
MsgBox("Unable to make Access connection. Error# " & Err.Number & " " & ErrorToString() & " " & ex.ToString, MsgBoxStyle.OkOnly, "Database Connection Error (OLEOPN1)")
Return False
Finally
builder.Clear()
builder = Nothing
End Try
End Function
Public Function OpenDBConnection(ByRef conn As OleDbConnection) As Boolean
'I know this is an extraneous function call but it is in transition from multiple prior uses and I thought I had better not exclude it from this post in case it mattered for some reason
OpenDBConnection = OpenAccessConnection(conn)
End Function
Error being returned intermittently:
I have read many of the posts on this topic and have not found a solution, and frankly am not sure where to look. Could this be coming from an earlier application error? Thread/STA issue? If so, what do I do about it? On the development machine, I will on occasion see a DisconnectedContext error, but have not seen the External component error which appears on PC's running the released version. Are these related? Also, there are some ADO (ADODB) connections being made to the database (still trying to replace/upgrade), but these are not open at the time this new connection is being made. But could it be a connection pooling issue? Thanks in advance for any help out there.
I retrieve it in my mainform:
Try
rs.Connection = con
cmd = "select * from cdcol.currency_rate"
rs.CommandText = cmd
res = rs.ExecuteReader
While res.Read
Dim currency = res.GetString("currency")
ComboBox2.Items.Add(currency)
End While
res.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
and this in my tabcontrol
Try
rs.Connection = con
cmd = "select * from cdcol.currency_rate where currency='" & ComboBox2.Text & "'"
rs.CommandText = cmd
res = rs.ExecuteReader
While res.Read
If sell.Checked = True Then
buy.Text = res.GetDouble("buy_rate")
coderate.Text = res.GetString("code")
End If
If buy.Checked = True Then
sell.Text = res.GetDouble("sell_rate")
coderate.Text = ("PHP")
End If
End While
res.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
when i log in there was an error,
what's wrong with my codes ?
please help me ..
A few things could be going on, hard to tell without all the code but I'll give you some ideas. I'm assuming this is a WinForms app (also assuming this is SQL Server)?
If you've verified that all your DataReader's are being closed properly then it is possible that you have two DataReaders actually trying to read at the same time if they're using a shared connection in your program (you say you're using a tab control and executing a query, if you have one reader running somewhere and then you click on a tab you could run into that scenario). If that is your desired behavior you can allow multiple recordsets by adding the multiple active result sets flag to your connection string:
https://msdn.microsoft.com/en-us/library/h32h3abf(v=vs.110).aspx
Something like this:
Dim connectionString As String = "Data Source=MSSQL1;" & _
"Initial Catalog=AdventureWorks;Integrated Security=SSPI;" & _
"MultipleActiveResultSets=True"
The MSDN article gives you much more info about it. In your scenario this will probably work. MSDN offers this though (which is your other option, use a connection per method you need it and dispose of it when you're done):
"MARS is not designed to remove all requirements for multiple
connections in an application. If an application needs true parallel
execution of commands against a server, multiple connections should be
used."
i searched google and stackoverflow alot but no solution
i was trying to pass multiple arguments in cmd
they are like in this way
Dim argu1 As String = "netsh wlan set hostednetwork mode = allow ssid=" + TextBox1.Text + " key=" + TextBox2.Text
Dim argu2 As String = "netsh wlan start hostednetwork"
Dim process As System.Diagnostics.Process = Nothing
Dim processStartInfo As System.Diagnostics.ProcessStartInfo
processStartInfo = New System.Diagnostics.ProcessStartInfo
processStartInfo.FileName = "cmd.exe"
processStartInfo.Verb = "runas"
and wrote arguments in this way
processStartInfo.Arguments = argu1 & argu2
processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
processStartInfo.UseShellExecute = True
Try
process = System.Diagnostics.Process.Start(processStartInfo)
Catch ex As Exception
MessageBox.Show(ex.Message, "Unknown Error !", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If Not (process Is Nothing) Then
process.Dispose()
End If
End Try
but nothing is happening
so plz tell me how can i pass multiple arguments
What did you expect to happen? You are executing
cmd.exe netsh wlan set hostednetwork mode = allow ssid=... key=...netsh wlan start hostednetwork
which simply starts a new instance of cmd.exe, ignoring all that netsh ... stuff.
Please have a look at the documentation of cmd.exe. In particular, I suspect that the /c command line switch might be what you are looking for. That said, you might want to consider calling netsh.exe directly or (even better) search for a way to do what you are trying to achieve with Windows API or the .NET library.
ok so im trying so send a email to a user who enters their email into a textbox. i got a basic idea of whats i should do but i am confused where i should put for , CMTPClient(),
the credentials, and from. what email should go there. i tryed puting in my email address and credentials but i keep getting this error " the SMTP server requires a sercure connection or the client was not autherticated". here is my code
Try
Dim username As String
username = TextBox1.Text
Dim SmtpServer As New SmtpClient("smtp.gmail.com")
Dim mail As New MailMessage()
SmtpServer.Credentials = New System.Net.NetworkCredential("what username goes
here", "what password goes here")
SmtpServer.Port = 587
mail = New MailMessage()
mail.From = New MailAddress("what email should i put here")
mail.To.Add(username)
mail.Subject = "Qustions"
mail.Body = "This is for testing your mother"
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
use SmtpServer.EnableSsl = True before calling SmtpServer.Send(mail)
"the SMTP server requires a secure connection or the client was not
authenticated"
means the SMTP Server works on a SSL Enabled (encrypted) connection
Keep in mind that gmail isn't just open for all to use. Otherwise, well, you know: spam. Right now spammers have to jump through all kinds of hoops to find or create usable smtp gateways. If any of the major providers left themselves open, think of all the spam you get right now and multiply it by about a 1000.
So you need to have an account with gmail to use their smtp server. More than that, if you send more than about 400 e-mails per day you may need either a special account with them, or an account with a special, reputable mass mailer. These mailers will charge you per message, but it's worth it, because otherwise more than a few messages per day will attract notice and result in anything you send being filtered as spam... and this while still in transit, before it even reaches the destination's mail host to be checked there as well. You're basically paying a nuisance fee, to ensure that your messages are in earnest, and not mass junk.
That out of the way, if you know your volume is low enough, and after you have a valid gmail account, you just need a few changes:
Try
Dim SmtpServer As New SmtpClient("smtp.gmail.com")
Dim mail As New MailMessage()
SmtpServer.Credentials = New System.Net.NetworkCredential("gmailusername#gmail.com", "your gmail password")
SmtpServer.EnableSsl = True
SmtpServer.Port = 587
mail = New MailMessage()
mail.From = New MailAddress("gmailusername#gmail.com")
mail.To.Add(TextBox1.Text)
mail.Subject = "Questions"
mail.Body = "This is for testing your mother"
SmtpServer.Send(mail)
MsgBox("mail sent")
Catch ex As Exception
MsgBox(ex.ToString)
End Try