473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Trying to send mail with an attachment

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
2 2480
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robbie De Sutter | last post by:
Hello, How do I open a new, empty e-mail message from the default e-mail client whereby the sender is given and a file is attached? Currently I use the command (vb.net): ---...
2
by: m_evergreen | last post by:
Errors: An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll Additional information: Could not access 'CDO.Message' object. innerexception is "Exception has...
2
by: Cimento Cola | last post by:
Hello all. Hope anyone can help me! I have this form, with: Please choose your file: (browse) The main purpose is the user to select a local file and then when he submits a mail should be...
4
by: Max | last post by:
hi I am using System.Web.Mail.MailMessage with System.Web.Mail.SmtpMail to send mail. now the my question is, Is it compulsory to add fields smtpauthenticate, sendusername and sendpassword...
3
by: =?Utf-8?B?SHVnaA==?= | last post by:
Hi There, I use follow code to send email inside VB.NET 2005. It does not work well. Error message of "Failure sending email" would occue. However, email was sent out sometimes. I am confused...
1
by: Chitu03 | last post by:
Hi I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know how can i get from database and then add to my mail....
1
by: hmbscully | last post by:
I am trying to send a complex mutli-part email with inline attachments between html pieces. I originally wrote the code in Perl with the MIME::Lite module, which worked fine. My attempts to...
5
by: pat | last post by:
Hi, i'am using an ac2K progrom which sends automaticle emails with an attachment. Since last week , a error occurs with number 2293. Our mail program is Outlook 2003. It's probably a matter...
1
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.