15. Januar 2009 16:37
15. Januar 2009 17:05
15. Januar 2009 17:38
Imports System.Net.Mail
Imports System.Net.Mime
Public Class clsMail
Function sendMail(ByVal from As String, ByVal mailto As String, ByVal mailsubject As String, ByVal mailbody As String, ByVal attachedfile As String) As String
' Set mailServerName to be the name of the mail server
' you wish to use to deliver this message
Dim mailServerName As String = "192.168.100.1"
Try
' MailMessage is used to represent the e-mail being sent
Using message As New MailMessage(from, mailto, mailsubject, mailbody)
Dim data As Attachment
data = New Attachment(attachedfile, MediaTypeNames.Application.Octet)
Dim disposition As ContentDisposition = data.ContentDisposition
disposition.CreationDate = System.IO.File.GetCreationTime(attachedfile)
disposition.ModificationDate = System.IO.File.GetLastWriteTime(attachedfile)
disposition.ReadDate = System.IO.File.GetLastAccessTime(attachedfile)
message.Attachments.Add(data)
' SmtpClient is used to send the e-mail
Dim mailClient As New SmtpClient(mailServerName)
' UseDefaultCredentials tells the mail client to use the
' Windows credentials of the account (i.e. user account)
' being used to run the application
mailClient.UseDefaultCredentials = True
' Send delivers the message to the mail server
mailClient.Send(message)
End Using
Return "Message sent with Attachment."
Catch ex As FormatException
Return ex.Message
Catch ex As SmtpException
Return ex.Message
End Try
End Function
Function sendMail(ByVal from As String, ByVal mailto As String, ByVal mailsubject As String, ByVal mailbody As String) As String
' Set mailServerName to be the name of the mail server
' you wish to use to deliver this message
Dim mailServerName As String = "192.168.100.1"
Try
' MailMessage is used to represent the e-mail being sent
Using message As New MailMessage(from, mailto, mailsubject, mailbody)
' SmtpClient is used to send the e-mail
Dim mailClient As New SmtpClient(mailServerName)
' UseDefaultCredentials tells the mail client to use the
' Windows credentials of the account (i.e. user account)
' being used to run the application
mailClient.UseDefaultCredentials = True
' Send delivers the message to the mail server
mailClient.Send(message)
End Using
Return "Message sent."
Catch ex As FormatException
Return ex.Message
Catch ex As SmtpException
Return ex.Message
End Try
End Function
End Class
16. Januar 2009 09:35