I wonder if anyone can help me. I am trying to send email from a windows form application and I can't work out how to send attachments. How does everyone else do it? I'm comunicating directly with the SMTP server. Is there an easier way?
Imports System.Web.Mail
Sub mailsender(ByVal mailto As String, ByVal msgbody As String, ByVal msgsubj As String, ByVal mailfrom As String, Optional ByVal attachment As String = "")
Try
Dim Message As New System.Web.Mail.MailMessage()
Dim attachmentenc As System.Web.Mail.MailAttachment()
Message.To = mailto
Message.From = mailfrom
Message.Body = msgbody
Message.Subject = msgsubj
Message.BodyFormat = Web.Mail.MailFormat.Html
If attachment <> "" Then
Message.Attachments.Add(attachment)
End If
System.Web.Mail.SmtpMail.SmtpServer = "62.105.167.3"
System.Web.Mail.SmtpMail.Send(Message)
Message = Nothing
Catch
MsgBox("Error Sending Mail")
End Try
end sub
Message.Attachments.Add(attachment)