Hej! "<img src= App,paht & "\bild\pid.jpg height=80 width=160>" Det är också så att app.path borde ligga utanför strängen - det är ett kommando för att ta reda på var på disken filen finns. På detta sätt så kommer hela url:en att visas. Nästa problem är nog att bilden faktiskt inte är åtkomlig från din datorn när man mailar någon annan så sökvägen borde peka till en bild som alla kommer åt, dvs på internet alternativt att det läggs som en attachment men då är koden lite annorlunda om jag inte minns fel.Bild i mail via cdo
Jag vill att en bild ska visas i mailet som jag skickar med cdo och vb6, alltså efter lite text vill jag att längst ner visa en bild, men får inte till det står bara invalid picture i en ruta.
Koden ser ut så här.
Dim objCDOMsg As New CDO.Message
Dim objCDOCon As New CDO.Configuration
Dim strSchemas As String
Dim strHTML
strSchemas = "http://schemas.microsoft.com/cdo/configuration/"
With objCDOCon.Fields
.Item(strSchemas & "sendusing") = 2
.Item(strSchemas & "smtpserver") = strSmpt
.Item(strSchemas & "smtpserverport") = 465
.Item(strSchemas & "smtpauthenticate") = 1
.Item(strSchemas & "sendusername") = strEmail
.Item(strSchemas & "sendpassword") = strEpass
.Item(strSchemas & "smtpconnectiontimeout") = 30
.Item(strSchemas & "smtpusessl") = 1
.Update
End With
sSend = sEpost
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Dim iMsg As New CDO.Message
strHTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & NL
strHTML = strHTML & "<HTML>"
strHTML = strHTML & " <HEAD>"
strHTML = strHTML & " <TITLE>Påminnelse</TITLE>"
strHTML = strHTML & " </HEAD>"
strHTML = strHTML & " <BODY><P>"
strHTML = strHTML & " <b> This is the test HTML message body</b></br><br>"
strHTML = strHTML & " <b> This is the test HTML message body</b></br><br>"
strHTML = strHTML & " <html><p>This is a picture.</p>" & _
"<img src= App,paht & "\bild\pid.jpg height=80 width=160>"
strHTML = strHTML & " </BODY>"
strHTML = strHTML & "</HTML>"
iMsg.HTMLBody = strHTML
' Construct your email
With objCDOMsg
.From = "info@zip.se"
.To = sSend
.Subject = "Information" ' Subject
.HTMLBody = strHTML
'.TextBody = ' Body
'.Sender = sFrom 'strEmail
'.ReplyTo = sFrom 'strEmail
'.AddAttachment
'Debug.Print "AntalFiler: " & sEpost
'.AddAttachment App.Path & "\Visa.txt" ' Your Attachment
Set .Configuration = objCDOCon
.Send
End With
Om någon ligger inne med denna kunskap skulle jag bli riktigt glad, står väldigt lite om just detta,
Tobbe
Sv: Bild i mail via cdo
Punkt istället för komma!
"<img src= App.paht & "\bild\pid.jpg height=80 width=160>"Sv:Bild i mail via cdo
"<img src='" & App.path & "\bild\pid.jpg" & "' height=80 width=160>"
Ett annat exempel där man faktiskt bifogar en fil, och inte en bild:
Deklaration:
Imports System.Web.Mail
Imports System.IO
Kod:
'TWO FUNCTIONS
'SAME EXCEPT FIRST TAKES A STRING FOR ATTACHMENT
'SECOND TAKES AN ARRAY LIST SO YOU CAN SEND MULTIPLE
'ATTACHMENTS
'FROM: Email address FRom
'TO: EMAIL address To
'Subject: Subject; Body: MessageText
'Optional CC, BCC: CC and bcc recipients
'SMTPSERVER: Optional, if not specified
'local machine is used
'AttachmentFile (first function: Optional, file name)
'AttachmentFiles (second function: Optional, list of
'attachments in form of an array list)
Public Sub SendMailOneAttachment(ByVal From As String, _
ByVal sendTo As String, ByVal Subject As String, _
ByVal Body As String, _
Optional ByVal AttachmentFile As String = "", _
Optional ByVal CC As String = "", _
Optional ByVal BCC As String = "", _
Optional ByVal SMTPServer As String = "")
Dim myMessage As MailMessage
Try
myMessage = New MailMessage()
With myMessage
.To = sendTo
.From = From
.Subject = Subject
.Body = Body
.BodyFormat = MailFormat.Text
'CAN USER MAILFORMAT.HTML if you prefer
If CC <> "" Then .Cc = CC
If BCC <> "" Then .Bcc = ""
If FileExists(AttachmentFile) Then _
.Attachments.Add(AttachmentFile)
End With
If SMTPServer <> "" Then _
SmtpMail.SmtpServer = SMTPServer
SmtpMail.Send(myMessage)
Catch myexp As Exception
Throw myexp
End Try
End Sub
Public Sub SendMailMultipleAttachments(ByVal From As String,_
ByVal sendTo As String, ByVal Subject As String, _
ByVal Body As String, _
Optional ByVal AttachmentFiles As ArrayList = Nothing, _
Optional ByVal CC As String = "", _
Optional ByVal BCC As String = "", _
Optional ByVal SMTPServer As String = "")
Dim myMessage As MailMessage
Dim i, iCnt As Integer
Try
myMessage = New MailMessage()
With myMessage
.To = sendTo
.From = From
.Subject = Subject
.Body = Body
.BodyFormat = MailFormat.Text
'CAN USER MAILFORMAT.HTML if you prefer
If CC <> "" Then .Cc = CC
If BCC <> "" Then .Bcc = ""
If Not AttachmentFiles Is Nothing Then
iCnt = AttachmentFiles.Count - 1
For i = 0 To iCnt
If FileExists(AttachmentFiles(i)) Then _
.Attachments.Add(AttachmentFiles(i))
Next
End If
End With
If SMTPServer <> "" Then _
SmtpMail.SmtpServer = SMTPServer
SmtpMail.Send(myMessage)
Catch myexp As Exception
Throw myexp
End Try
End Sub
Private Function FileExists(ByVal FileFullPath As String) _
As Boolean
If Trim(FileFullPath) = "" Then Return False
Dim f As New IO.FileInfo(FileFullPath)
Return f.Exists
End Function