Attaching a file to generated email
-
Hi All, I've got the following code, which runs an exe with some switches and then sends the log file to me, or at least it's supposed to. I receive the email ok, but no attachment.. the code compiles fine.. has anyone any ideas??
MyProcess.StartInfo.FileName = "printmig.exe" MyProcess.StartInfo.WorkingDirectory = "c:\print backup" MyProcess.StartInfo.Arguments = "printmig.exe /b /i" MyProcess.Start() MyProcess.WaitForExit() Dim objMail As New System.Net.Mail.MailMessage() Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient Dim Mailmsg As New System.Net.Mail.MailMessage Mailmsg.To.Clear() Mailmsg.To.Add(New System.Net.Mail.MailAddress("receivers address")) Mailmsg.From = New System.Net.Mail.MailAddress("senders address") Mailmsg.Subject = "(subject text)" Dim attachment As New System.Net.Mail.Attachment("C:\file.log") 'create the attachment objMail.Attachments.Add(attachment) 'add the attachment Try Mailmsg.Body = "" obj.Host = "external smtp server" ' Modify to YOUR smtp server obj.Send(Mailmsg) Catch ex As Exception Write("Error: " & ex.ToString())
Cheers nhsal69 -
Hi All, I've got the following code, which runs an exe with some switches and then sends the log file to me, or at least it's supposed to. I receive the email ok, but no attachment.. the code compiles fine.. has anyone any ideas??
MyProcess.StartInfo.FileName = "printmig.exe" MyProcess.StartInfo.WorkingDirectory = "c:\print backup" MyProcess.StartInfo.Arguments = "printmig.exe /b /i" MyProcess.Start() MyProcess.WaitForExit() Dim objMail As New System.Net.Mail.MailMessage() Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient Dim Mailmsg As New System.Net.Mail.MailMessage Mailmsg.To.Clear() Mailmsg.To.Add(New System.Net.Mail.MailAddress("receivers address")) Mailmsg.From = New System.Net.Mail.MailAddress("senders address") Mailmsg.Subject = "(subject text)" Dim attachment As New System.Net.Mail.Attachment("C:\file.log") 'create the attachment objMail.Attachments.Add(attachment) 'add the attachment Try Mailmsg.Body = "" obj.Host = "external smtp server" ' Modify to YOUR smtp server obj.Send(Mailmsg) Catch ex As Exception Write("Error: " & ex.ToString())
Cheers nhsal69You are adding the attachment to objMail
objMail.Attachments.Add(attachment)
but you are sending Mailmsgobj.Send(Mailmsg)
I know the language. I've read a book. - _Madmatt
-
Hi All, I've got the following code, which runs an exe with some switches and then sends the log file to me, or at least it's supposed to. I receive the email ok, but no attachment.. the code compiles fine.. has anyone any ideas??
MyProcess.StartInfo.FileName = "printmig.exe" MyProcess.StartInfo.WorkingDirectory = "c:\print backup" MyProcess.StartInfo.Arguments = "printmig.exe /b /i" MyProcess.Start() MyProcess.WaitForExit() Dim objMail As New System.Net.Mail.MailMessage() Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient Dim Mailmsg As New System.Net.Mail.MailMessage Mailmsg.To.Clear() Mailmsg.To.Add(New System.Net.Mail.MailAddress("receivers address")) Mailmsg.From = New System.Net.Mail.MailAddress("senders address") Mailmsg.Subject = "(subject text)" Dim attachment As New System.Net.Mail.Attachment("C:\file.log") 'create the attachment objMail.Attachments.Add(attachment) 'add the attachment Try Mailmsg.Body = "" obj.Host = "external smtp server" ' Modify to YOUR smtp server obj.Send(Mailmsg) Catch ex As Exception Write("Error: " & ex.ToString())
Cheers nhsal69obj.Send(Mailmsg) Mailmsg.Send(Mailmsg)
Rajesh B --> A Poor Workman Blames His Tools <--
-
obj.Send(Mailmsg) Mailmsg.Send(Mailmsg)
Rajesh B --> A Poor Workman Blames His Tools <--