hey guys, I'm a vb newbie, so if someone can help me with this, I would appreciate it. I'm trying to build a quick little VB.net form that when opened will send me an email attachment with the event logs from my computers at work. I have about 10 of them and no one can seem to remember what error messages they get, so it would be helpful for me to be able to have a list of them, and I'm trying to learn more about SMTP in VB.net. Here's some of my code:
Code:
Imports system.web.mail
Public Class Form1
Inherits System.Windows.Forms.Form
Dim Attachment As System.Web.Mail.MailAttachment
Private Sub newmailer(ByVal smtp, ByVal messageto, ByVal messagefrom, ByVal subject, ByVal message)
Dim myMessage As New MailMessage
Dim myMailServer As SmtpMail
myMessage.BodyFormat = MailFormat.Html
myMessage.Priority = MailPriority.Normal
myMessage.From = messagefrom
myMessage.To = messageto
myMessage.Subject = subject
myMessage.Body = message & vbCrLf
myMessage.Body &= "<font color=blue></font><br>" & vbCrLf & _
"<font color=red></font><br>" & vbCrLf
myMessage.Attachments.Add("c:\path\filename.ext")
myMailServer.SmtpServer = smtp
myMailServer.Send(myMessage)
myMessage = Nothing
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
'I have included the call statements in the form load so I 'can just schedule this executable to load, send the 'attachment and then close.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim smtp As String
Dim subject As String
Dim messageto As String
Dim messagefrom As String
Dim message As String
smtp = "smtpservername"
messageto = "myemail@domain.com"
messagefrom = "fromusername@domain.com"
subject = "subject line"
message = "message"
Call newmailer(smtp, messageto, messagefrom, subject, message)
Me.Close()
End Sub
End Class