I've got a multiple step process, end goal is to send an Excel file by e-mail using VB.NET.
Original data is in .txt report, so using Monarch V9 to create an Excel file from a summary.
Then want to create either a Windows app or service to e-mail the report.
I can get the file to e-mail just fine, but can't open from Outlook - file is corrupted and I get the "Windows has encountered an error".
Original file is OK.
Here's the code:
Imports System.web.mail
Imports System.IO
Imports System.IO.File
Private Sub btnSendEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendEmail.Click
Dim email As New System.Web.Mail.MailMessage
Dim attach As MailAttachment
Dim strPath As String
Dim strTo As String = "john.doe@hotmail.com"
Dim strAttach As String
attach = New MailAttachment("H:\file.xls")
email.To = strTo
email.From = "DoNotReply@mail.com"
email.Subject = "test excel"
email.Attachments.Clear()
email.Attachments.Add(attach)
System.Web.Mail.SmtpMail.SmtpServer = "MailServer"
System.Web.Mail.SmtpMail.Send(email)
End Sub
I know I must be missing some type of encoding or formatting. Can you help? I can cut & paste from the MS Windows error if that will shed any light.
Thanks!
Original data is in .txt report, so using Monarch V9 to create an Excel file from a summary.
Then want to create either a Windows app or service to e-mail the report.
I can get the file to e-mail just fine, but can't open from Outlook - file is corrupted and I get the "Windows has encountered an error".
Original file is OK.
Here's the code:
Imports System.web.mail
Imports System.IO
Imports System.IO.File
Private Sub btnSendEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendEmail.Click
Dim email As New System.Web.Mail.MailMessage
Dim attach As MailAttachment
Dim strPath As String
Dim strTo As String = "john.doe@hotmail.com"
Dim strAttach As String
attach = New MailAttachment("H:\file.xls")
email.To = strTo
email.From = "DoNotReply@mail.com"
email.Subject = "test excel"
email.Attachments.Clear()
email.Attachments.Add(attach)
System.Web.Mail.SmtpMail.SmtpServer = "MailServer"
System.Web.Mail.SmtpMail.Send(email)
End Sub
I know I must be missing some type of encoding or formatting. Can you help? I can cut & paste from the MS Windows error if that will shed any light.
Thanks!