Mega Code Archive

 
Categories / VB.Net Tutorial / Socket Network
 

Send an Email

Imports System Imports System.Web Imports System.Web.Mail Imports System.Data Imports System.Drawing Imports System.Collections Imports System.Windows.Forms Imports System.ComponentModel Public Class Tester     Public Shared Sub Main              Dim mails As New MailMessage         mails.From = "from@from.net"         mails.To = "to@to.net"         mails.Subject = "message"         mails.Cc = "cc@cc.net"         mails.Body = "this is the message"         mails.BodyEncoding = System.Text.Encoding.UTF8         mails.BodyFormat = MailFormat.Html         mails.Attachments.Add("c:\\test.txt")         SmtpMail.Send(mails)              End Sub End Class Unhandled Exception: System.InvalidCastException: Unable to cast object of type 'System.String' to t ype 'System.Web.Mail.MailAttachment'. at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at Tester.Main()