EDN Admin
Well-known member
I am teaching myself vb.net and wanted to change this code to have an embedded mail.boby from a text file instead of the file attachment. can someone help? Code spippet below and where I need help is mail.Body = (<span style="color:#a31515 "tracertALL.txt")
that just puts the name of the file NOT the contents of the file. This code is a CMDWrapper that runs a batch file and I want the contents of a trace route that is pipe to a file >> tracertALL.txt . thanks any help is greatly
appreciated!
<span style="font-family:Consolas; color:blue; font-size:9.5pt Imports<span style="font-family:Consolas; font-size:9.5pt System.Net.Mail
<span style="font-family:Consolas; color:blue; font-size:9.5pt Public<span style="font-family:Consolas; font-size:9.5pt
<span style="color:blue Class <span style="color:#2b91af Form1
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private Results <span style="color:blue As
<span style="color:blue String
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private <span style="color:blue Delegate <span style="color:blue
Sub <span style="color:#2b91af delUpdate()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private Finished <span style="color:blue As
<span style="color:blue New <span style="color:#2b91af delUpdate(<span style="color:blue AddressOf UpdateText)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private <span style="color:blue Sub UpdateText()
<span style="font-family:Consolas; font-size:9.5pt <span>
txtResults.Text = Results
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue Sub
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private <span style="color:blue Sub CMDAutomate()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim FileContent <span style="color:blue As
<span style="color:blue String = <span style="color:blue My.Resources.mybatchfile
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim Filename <span style="color:blue As
<span style="color:blue String = <span style="color:#a31515 "trs01all.bat"
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue My.Computer.FileSystem.WriteAllText(Filename, FileContent,
<span style="color:blue False, System.Text.<span style="color:#2b91af Encoding.ASCII)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim myprocess <span style="color:blue As
<span style="color:blue New <span style="color:#2b91af Process
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim StartInfo <span style="color:blue As
<span style="color:blue New System.Diagnostics.<span style="color:#2b91af ProcessStartInfo
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.FileName = <span style="color:#a31515 "trs01all.bat" <span style="color:green
starts cmd window
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.Arguments = (txtCommand.Text)
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.RedirectStandardInput = <span style="color:blue True
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.RedirectStandardOutput = <span style="color:blue True
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.UseShellExecute = <span style="color:blue False <span style="color:green
required to redirect
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.CreateNoWindow = <span style="color:blue True <span style="color:green
creates no cmd window
<span style="font-family:Consolas; font-size:9.5pt <span>
myprocess.StartInfo = StartInfo
<span style="font-family:Consolas; font-size:9.5pt <span>
myprocess.Start()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim SR <span style="color:blue As System.IO.<span style="color:#2b91af StreamReader = myprocess.StandardOutput
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim SW <span style="color:blue As System.IO.<span style="color:#2b91af StreamWriter = myprocess.StandardInput
<span style="font-family:Consolas; font-size:9.5pt <span>
SW.WriteLine(txtCommand.Text) <span style="color:green the command you wish to run.....
<span style="font-family:Consolas; font-size:9.5pt <span>
SW.WriteLine(<span style="color:#a31515 "exit") <span style="color:green
exits command prompt window
<span style="font-family:Consolas; font-size:9.5pt <span>
Results = SR.ReadToEnd <span style="color:green returns results of the command window
<span style="font-family:Consolas; font-size:9.5pt <span>
SW.Close()
<span style="font-family:Consolas; font-size:9.5pt <span> <span>
SR.Close()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Try
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim SmtpServer <span style="color:blue As
<span style="color:blue New <span style="color:#2b91af SmtpClient()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim mail <span style="color:blue As
<span style="color:blue New <span style="color:#2b91af MailMessage()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green SmtpServer.Credentials = New Net.NetworkCredential("username@email.com", "password")
<span style="font-family:Consolas; font-size:9.5pt <span>
SmtpServer.Port = 25
<span style="font-family:Consolas; font-size:9.5pt <span>
<span> SmtpServer.Host = <span style="color:#a31515
"smtprelay.email.com"
<span style="font-family:Consolas; font-size:9.5pt <span>
mail = <span style="color:blue New <span style="color:#2b91af MailMessage()
<span style="font-family:Consolas; font-size:9.5pt <span>
mail.From = <span style="color:blue New <span style="color:#2b91af
MailAddress(<span style="color:#a31515 "noreply@email.com")
<span style="font-family:Consolas; font-size:9.5pt <span>
mail.To.Add(txtCommand.Text)
<span style="font-family:Consolas; font-size:9.5pt <span>
mail.Subject = <span style="color:#a31515 "<street w:st="on
<address>Automated Trace Route</address>
</street> log file"
<span style="font-family:Consolas; font-size:9.5pt <span>
mail.Body = (<span style="color:#a31515 "tracertALL.txt") THIS IS WHERE I NEED HELP!
<span style="font-family:Consolas; font-size:9.5pt <span>
SmtpServer.Send(mail)
<span style="font-family:Consolas; font-size:9.5pt <span>
MsgBox(<span style="color:#a31515 "eMail sent successfully!")
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Catch ex <span style="color:blue As
<span style="color:#2b91af Exception
<span style="font-family:Consolas; font-size:9.5pt <span>
MsgBox(ex.ToString)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue Try
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue My.Computer.FileSystem.DeleteFile(<span style="color:#a31515 "trs01all.bat")
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green invokes Finished delegate, which updates textbox with the results text
<span style="font-family:Consolas; font-size:9.5pt <span>
Invoke(Finished)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue Sub
<span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private <span style="color:blue Sub txtResults_TextChanged(<span style="color:blue ByVal sender
<span style="color:blue As System.<span style="color:#2b91af Object,
<span style="color:blue ByVal e <span style="color:blue As System.<span style="color:#2b91af EventArgs)
<span style="color:blue Handles txtResults.TextChanged
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue Sub
<span style="font-family:Consolas; color:blue; font-size:9.5pt End<span style="font-family:Consolas; font-size:9.5pt
<span style="color:blue Class
View the full article
that just puts the name of the file NOT the contents of the file. This code is a CMDWrapper that runs a batch file and I want the contents of a trace route that is pipe to a file >> tracertALL.txt . thanks any help is greatly
appreciated!
<span style="font-family:Consolas; color:blue; font-size:9.5pt Imports<span style="font-family:Consolas; font-size:9.5pt System.Net.Mail
<span style="font-family:Consolas; color:blue; font-size:9.5pt Public<span style="font-family:Consolas; font-size:9.5pt
<span style="color:blue Class <span style="color:#2b91af Form1
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private Results <span style="color:blue As
<span style="color:blue String
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private <span style="color:blue Delegate <span style="color:blue
Sub <span style="color:#2b91af delUpdate()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private Finished <span style="color:blue As
<span style="color:blue New <span style="color:#2b91af delUpdate(<span style="color:blue AddressOf UpdateText)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private <span style="color:blue Sub UpdateText()
<span style="font-family:Consolas; font-size:9.5pt <span>
txtResults.Text = Results
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue Sub
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private <span style="color:blue Sub CMDAutomate()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim FileContent <span style="color:blue As
<span style="color:blue String = <span style="color:blue My.Resources.mybatchfile
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim Filename <span style="color:blue As
<span style="color:blue String = <span style="color:#a31515 "trs01all.bat"
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue My.Computer.FileSystem.WriteAllText(Filename, FileContent,
<span style="color:blue False, System.Text.<span style="color:#2b91af Encoding.ASCII)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim myprocess <span style="color:blue As
<span style="color:blue New <span style="color:#2b91af Process
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim StartInfo <span style="color:blue As
<span style="color:blue New System.Diagnostics.<span style="color:#2b91af ProcessStartInfo
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.FileName = <span style="color:#a31515 "trs01all.bat" <span style="color:green
starts cmd window
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.Arguments = (txtCommand.Text)
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.RedirectStandardInput = <span style="color:blue True
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.RedirectStandardOutput = <span style="color:blue True
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.UseShellExecute = <span style="color:blue False <span style="color:green
required to redirect
<span style="font-family:Consolas; font-size:9.5pt <span>
StartInfo.CreateNoWindow = <span style="color:blue True <span style="color:green
creates no cmd window
<span style="font-family:Consolas; font-size:9.5pt <span>
myprocess.StartInfo = StartInfo
<span style="font-family:Consolas; font-size:9.5pt <span>
myprocess.Start()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim SR <span style="color:blue As System.IO.<span style="color:#2b91af StreamReader = myprocess.StandardOutput
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim SW <span style="color:blue As System.IO.<span style="color:#2b91af StreamWriter = myprocess.StandardInput
<span style="font-family:Consolas; font-size:9.5pt <span>
SW.WriteLine(txtCommand.Text) <span style="color:green the command you wish to run.....
<span style="font-family:Consolas; font-size:9.5pt <span>
SW.WriteLine(<span style="color:#a31515 "exit") <span style="color:green
exits command prompt window
<span style="font-family:Consolas; font-size:9.5pt <span>
Results = SR.ReadToEnd <span style="color:green returns results of the command window
<span style="font-family:Consolas; font-size:9.5pt <span>
SW.Close()
<span style="font-family:Consolas; font-size:9.5pt <span> <span>
SR.Close()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Try
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim SmtpServer <span style="color:blue As
<span style="color:blue New <span style="color:#2b91af SmtpClient()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim mail <span style="color:blue As
<span style="color:blue New <span style="color:#2b91af MailMessage()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green SmtpServer.Credentials = New Net.NetworkCredential("username@email.com", "password")
<span style="font-family:Consolas; font-size:9.5pt <span>
SmtpServer.Port = 25
<span style="font-family:Consolas; font-size:9.5pt <span>
<span> SmtpServer.Host = <span style="color:#a31515
"smtprelay.email.com"
<span style="font-family:Consolas; font-size:9.5pt <span>
mail = <span style="color:blue New <span style="color:#2b91af MailMessage()
<span style="font-family:Consolas; font-size:9.5pt <span>
mail.From = <span style="color:blue New <span style="color:#2b91af
MailAddress(<span style="color:#a31515 "noreply@email.com")
<span style="font-family:Consolas; font-size:9.5pt <span>
mail.To.Add(txtCommand.Text)
<span style="font-family:Consolas; font-size:9.5pt <span>
mail.Subject = <span style="color:#a31515 "<street w:st="on
<address>Automated Trace Route</address>
</street> log file"
<span style="font-family:Consolas; font-size:9.5pt <span>
mail.Body = (<span style="color:#a31515 "tracertALL.txt") THIS IS WHERE I NEED HELP!
<span style="font-family:Consolas; font-size:9.5pt <span>
SmtpServer.Send(mail)
<span style="font-family:Consolas; font-size:9.5pt <span>
MsgBox(<span style="color:#a31515 "eMail sent successfully!")
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Catch ex <span style="color:blue As
<span style="color:#2b91af Exception
<span style="font-family:Consolas; font-size:9.5pt <span>
MsgBox(ex.ToString)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue Try
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue My.Computer.FileSystem.DeleteFile(<span style="color:#a31515 "trs01all.bat")
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green invokes Finished delegate, which updates textbox with the results text
<span style="font-family:Consolas; font-size:9.5pt <span>
Invoke(Finished)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue Sub
<span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private <span style="color:blue Sub txtResults_TextChanged(<span style="color:blue ByVal sender
<span style="color:blue As System.<span style="color:#2b91af Object,
<span style="color:blue ByVal e <span style="color:blue As System.<span style="color:#2b91af EventArgs)
<span style="color:blue Handles txtResults.TextChanged
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue Sub
<span style="font-family:Consolas; color:blue; font-size:9.5pt End<span style="font-family:Consolas; font-size:9.5pt
<span style="color:blue Class
View the full article