Trying to send mail with an attachment

  • Thread starter Thread starter Robert Dufour
  • Start date Start date
R

Robert Dufour

I tried using (vs2003 Vb.Net)
Public Sub SendEmail( _

ByVal Recipient As String, _

ByVal Sender As String, _

ByVal Subject As String, _

ByVal Message As String, _

ByVal Server As String, _

Optional ByVal Attachments As String = "")

' Parameters: Recipient - recipient's address (e.g.,
"(e-mail address removed)")

' Sender - sender's email address (e.g., "(e-mail address removed)")

' Subject - text for email subject.

' Message - complete text of body of email message.

' Server - server to use, or blank to use local machine's default

' SMTP server (if applicable).

Dim msg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage

' To and From are required by SmtpMail.

msg.To = Recipient

msg.From = Sender

msg.Subject = Subject

msg.Body = Message

msg.BodyFormat = System.Web.Mail.MailFormat.Text

System.Web.Mail.SmtpMail.SmtpServer = Server

System.Web.Mail.SmtpMail.Send(msg)

End Sub

But I can't add an attachment. When I try setting msg.attachments =
attachments I get msg say attcahment property is readOnly



How can I send an e-mail with an attachment from within my code?



Thanks for any help.

Bob
 
Back
Top