|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Trying to send mail with an attachmentPublic 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., "geo***@whitehouse.gov") ' Sender - sender's email address (e.g., "b***@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 msg.Attachments.Add(New MailAttachment("c:\\temp\\annual-report.pdf"))
-- Show quoteHide quoteGet a powerful web, database, application, and email hosting with KJM Solutions http://www.kjmsolutions.com "Robert Dufour" <bduf***@sgiims.com> wrote in message news:eLdeXnLNGHA.3196@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., > "geo***@whitehouse.gov") > > ' Sender - sender's email address (e.g., "b***@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 > > > > Thanks
Show quoteHide quote "vbnetdev" <vbnetdev@community.nospam> wrote in message news:%23MarcxLNGHA.2124@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" <bduf***@sgiims.com> wrote in message > news:eLdeXnLNGHA.3196@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., > > "geo***@whitehouse.gov") > > > > ' Sender - sender's email address (e.g., "b***@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 > > > > > > > > > > |
|||||||||||||||||||||||