Send email with an attachment by smtp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hung52
    New Member
    • Jan 2008
    • 5

    Send email with an attachment by smtp

    What is a exact option for Attachement on the sending mail with smtp.
    I got an error : can't assign to read-only property
    ....
    strPdffile = "H:\ARCTest \" & Pdffile
    ....
    With iMsg
    .Configuration = iCfg
    '.Subject = "Example Subject"
    .Subject = "FPB - CAD"
    .To = "hng@faisalpriv atebank.com"
    .BCC = "mng@faisalpriv atebank.com"
    .Attachments.Ad d.filename = strPdffile
    .TextBody = "With the complinents from FPB - CAD team"
    .Send
    End With



    if I did :

    .Attachments.Ad d(strPdffile)

    I got the error : Type Mismatch

    Someone may gift me an solution. Thank you in advanced.
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    #2
    i use this and it works fine:
    [code=vbnet]
    Try

    Dim EMsg As New System.Net.Mail .MailMessage
    EMsg.From = New System.Net.Mail .MailAddress("F romaddress")
    EMsg.To.Add("to address")
    EMsg.Subject = "Test"
    EMsg.Body = "Hello"
    Dim smtp As New System.Net.Mail .SmtpClient("Se rver", port)
    smtp.EnableSsl = True
    If My.User.IsAuthe nticated = True Then
    smtp.UseDefault Credentials = False
    smtp.Credential s = New System.Net.Netw orkCredential(" login", "password")
    End If

    '--------
    Dim att As Attachment
    att = New Attachment(Path & "MRF.zip")
    EMsg.Attachment s.Add(att)
    '----------
    smtp.Send(EMsg)
    'MsgBox("Mail Sent")
    Catch Send_Mail As Exception
    MsgBox(Send_Mai l.ToString)
    End Try
    [/code]

    NOTE:
    Most isp block you from sending emails from their smtp server using thirdparty apps... although google doesnt

    smtp.gmail.com
    port 587

    Comment

    • hung52
      New Member
      • Jan 2008
      • 5

      #3
      Thank you Jamesd0142,
      but i have no vb.net .
      Anywhere, I found for my solution.
      The correct coding :
      .....
      .AddAttachment Path:\Filename
      ....
      have a nice day

      Comment

      Working...