2014-07-25 6 views
0

나는 폴더에서 jpg 이미지를 찾는이 응용 프로그램을 가지고 있으며 jpeg가 클라이언트에 전자 메일을 보내면 jpeg에서 데이터를 보낼 수 있지만 이미지를 메일에 첨부하는 방법은 무엇인지 찾아야합니다. 이 시도했지만이 오류가 발생했습니다 system.io .__ error.winioerror (int32 오류 코드 문자열 maybefullpath).이메일을 보내는 동안 이미지 첨부

Dim DirSearch As IO.FileInfo() = FileDirInfo.GetFiles("*.jpg") 
      Dim FileInfo As IO.FileInfo 

      Dim FileDir, FileName As String 
      FileDir = FileDirInfo.ToString 


For Each FileInfo In DirSearch 
      'for any files found, Split the filename into strings 
      FileName = FileInfo.ToString 

      Dim attachment As System.Net.Mail.Attachment 
      attachment = New System.Net.Mail.Attachment(FileName) 

       Dim attachment As System.Net.Mail.Attachment 
       attachment = New System.Net.Mail.Attachment(FileName) 

       Dim SmtpServer As New SmtpClient 
       Dim mail As New MailMessage 
       SmtpServer.Credentials = New Net.NetworkCredential("pramm", "roar")(//fake) 
       'SmtpServer1.EnableSsl = True 
       SmtpServer.Port = 587 
       SmtpServer.Host = "email.loror.ac.uk" 
       mail = New MailMessage 
       mail.From = New MailAddress("[email protected]") 
       mail.To.Add("[email protected]") 
       mail.Subject = "Alert" 
       mail.Body = "Vehicle " & VRM & " captured on " & Camera & " at " & TimeStr & " on the date " & DateStr 
     attachment = New System.Net.Mail.Attachment(FileName) 
      'mail.Attachments.Add(attachment) 
       SmtpServer.Send(mail) 

답변

0

이것은 HTML 형식의 전자 메일 및 첨부 파일에 사용하는 코드입니다.

첨부 파일을 이메일의 HTML 코드에 포함하도록 HTML 코드를 넣을 수도 있습니다.

''' <summary> 
''' Sends the HTML-type email and possible attached files to the given email addresses. 
''' </summary> 
Public Sub SendEmail(ByVal fromAddress As String, _ 
      ByVal fromName As String, _ 
      ByVal toAddresses As String(), _ 
      ByVal subject As String, _ 
      ByVal body As String, _ 
      Optional ByVal attachedFilePaths As List(Of String) = Nothing) 


    Dim oMsg As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage() 

    Dim addrFrom As New System.Net.Mail.MailAddress(fromAddress, fromName) 
    oMsg.From = addrFrom 

    For i As Integer = 0 To toAddresses.Length - 1 
     Dim address As New System.Net.Mail.MailAddress(toAddresses(i)) 
     oMsg.To.Add(address) 
    Next 

    oMsg.Subject = subject 

    oMsg.Body = body 

    oMsg.IsBodyHtml = True 

    If attachedFilePaths IsNot Nothing Then 
     For Each path As String In attachedFilePaths 
      Dim oAttch As System.Net.Mail.Attachment = New System.Net.Mail.Attachment(path) 
      oMsg.Attachments.Add(oAttch) 
     Next 
    End If 

    '--- 
    'GENERIC: 
    Dim client As New System.Net.Mail.SmtpClient(emailSenderHost, emailSenderPort) 
    Dim myLogin As New Net.NetworkCredential(emailSenderUsername, emailSenderPassword) 
    client.EnableSsl = False 

    client.EnableSsl = False 
    client.UseDefaultCredentials = True 
    client.Credentials = myLogin 
    client.EnableSsl = emailSenderEnableSsl 
    client.Send(oMsg) 

End Sub 
0

아래 내용이 도움이되는지 확인하십시오.

  • 이미지가 일부 프로세스에 의해 생성 된 경우 프로세스가 올바르게 처리하는지 확인하십시오. 또는 수동으로 이미지를 배치 해보십시오.
  • 응용 프로그램 풀에 폴더에 대한 사용 권한이 있는지 확인하십시오.

기본 테스트로 응용 프로그램의 루트 아래에 샘플 디렉토리를 만들고 수동으로 jpg를 배치 할 수 있습니다. 그리고이 디렉토리를 사용하기 위해 필요한 변경을 한 후에 응용 프로그램을 실행하십시오.

관련 문제