Trying to send mail with an attachment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Dufour

    #1

    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.,
    "george@whiteho use.gov")

    ' Sender - sender's email address (e.g., "bill@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.Tex t

    System.Web.Mail .SmtpMail.SmtpS erver = 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




  • vbnetdev

    #2
    Re: Trying to send mail with an attachment

    msg.Attachments .Add(New MailAttachment( "c:\\temp\\annu al-report.pdf"))

    --
    Get a powerful web, database, application, and email hosting with KJM
    Solutions




    "Robert Dufour" <bdufour@sgiims .com> wrote in message
    news:eLdeXnLNGH A.3196@TK2MSFTN GP09.phx.gbl...[color=blue]
    >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.,
    > "george@whiteho use.gov")
    >
    > ' Sender - sender's email address (e.g., "bill@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.Tex t
    >
    > System.Web.Mail .SmtpMail.SmtpS erver = 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
    >
    >
    >
    >[/color]


    Comment

    • Robert Dufour

      #3
      Re: Trying to send mail with an attachment

      Thanks
      "vbnetdev" <vbnetdev@commu nity.nospam> wrote in message
      news:%23MarcxLN GHA.2124@TK2MSF TNGP14.phx.gbl. ..[color=blue]
      > msg.Attachments .Add(New MailAttachment( "c:\\temp\\annu al-report.pdf"))
      >
      > --
      > Get a powerful web, database, application, and email hosting with KJM
      > Solutions
      > http://www.kjmsolutions.com
      >
      >
      >
      > "Robert Dufour" <bdufour@sgiims .com> wrote in message
      > news:eLdeXnLNGH A.3196@TK2MSFTN GP09.phx.gbl...[color=green]
      > >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.,
      > > "george@whiteho use.gov")
      > >
      > > ' Sender - sender's email address (e.g., "bill@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.Tex t
      > >
      > > System.Web.Mail .SmtpMail.SmtpS erver = 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
      > >
      > >
      > >
      > >[/color]
      >
      >[/color]



      Comment

      Working...