Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Attaching a file to generated email

Attaching a file to generated email

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpsysadminhelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nhsal69
    wrote on last edited by
    #1

    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

    N R 2 Replies Last reply
    0
    • N 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 nhsal69

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      You are adding the attachment to objMail objMail.Attachments.Add(attachment) but you are sending Mailmsg obj.Send(Mailmsg)


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • N 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 nhsal69

        R Offline
        R Offline
        Rajesh Anuhya
        wrote on last edited by
        #3

        obj.Send(Mailmsg) Mailmsg.Send(Mailmsg)

        Rajesh B --> A Poor Workman Blames His Tools <--

        N 1 Reply Last reply
        0
        • R Rajesh Anuhya

          obj.Send(Mailmsg) Mailmsg.Send(Mailmsg)

          Rajesh B --> A Poor Workman Blames His Tools <--

          N Offline
          N Offline
          nhsal69
          wrote on last edited by
          #4

          Doh! thanks for that... I'll just get my coat.. TAXI!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups