By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,890 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,890 IT Pros & Developers. It's quick & easy.

Trying to send mail with an attachment

P: n/a
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.,
"ge****@whitehouse.gov")

' Sender - sender's email address (e.g., "bi**@microsoft.com")

' 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


Feb 18 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
msg.Attachments.Add(New MailAttachment("c:\\temp\\annual-report.pdf"))

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com

"Robert Dufour" <bd*****@sgiims.com> wrote in message
news:eL**************@TK2MSFTNGP09.phx.gbl...
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.,
"ge****@whitehouse.gov")

' Sender - sender's email address (e.g., "bi**@microsoft.com")

' 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

Feb 18 '06 #2

P: n/a
Thanks
"vbnetdev" <vb******@community.nospam> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
msg.Attachments.Add(New MailAttachment("c:\\temp\\annual-report.pdf"))

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com

"Robert Dufour" <bd*****@sgiims.com> wrote in message
news:eL**************@TK2MSFTNGP09.phx.gbl...
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.,
"ge****@whitehouse.gov")

' Sender - sender's email address (e.g., "bi**@microsoft.com")

' 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



Feb 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.