Tamiryosef
Active member
- Joined
- May 2, 2022
- Messages
- 36
- Programming Experience
- 1-3
hi guys
i have program that open a excel sheet that will get data form my App
after the user close the excel sheet i like to attach it to gmail out massage and send it .
this is me code ,i remove the email config and password because security
what i want to check if the excel sheet is close by the user and then attach it to email
i have program that open a excel sheet that will get data form my App
after the user close the excel sheet i like to attach it to gmail out massage and send it .
this is me code ,i remove the email config and password because security
what i want to check if the excel sheet is close by the user and then attach it to email
email code:
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
xlApp = New Excel.ApplicationClass
xlApp.Visible = True
Dim datastart As Date = Date.Now
xlWorkBook = xlApp.Workbooks.Open(files)
xlWorkSheet = xlWorkBook.Worksheets("Invoice Template")
xlWorkSheet.Cells(2, 2) = Descriptiontxt.Text
Dim dataend As Date = Date.Now
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
End_Excel_App(datastart, dataend)
If xlWorkBook Is Nothing Then
Dim mail As New MailMessage()
Dim SmtpServer As New SmtpClient("smtp.gmail.com")
mail.From = New MailAddress("my email")
mail.[To].Add("send to email")
mail.Subject = "Test Mail - 1"
mail.Body = "mail with attachment"
Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment(files)
mail.Attachments.Add(attachment)
SmtpServer.Port = 587
SmtpServer.Credentials = New System.Net.NetworkCredential("email", "password")
SmtpServer.EnableSsl = True
SmtpServer.Send(mail)
MessageBox.Show("mail Send")
End If
End Sub