-1

im using vbscript CDO for mail sending but i want to attachment as a body of the email can you please suggest me.

strSMTPFrom = "kampati.vinay@testing.in"
strSMTPTo = "kampati.vinay@testing.in"
strSMTPRelay = "testing.in"
strTextBody = "MDaemon Q status"
strSubject = "MDaemon Q status"
strAttachment = "C:\MDaemon\output.txt"

Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
oMessage.Configuration.Fields.Update

oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
oMessage.AddAttachment strAttachment

oMessage.Send
user692942
  • 16,398
  • 7
  • 76
  • 175
Vinay
  • 1
  • 3
  • If you want the content of `output.txt` to be the `TextBody`, you will need to load the content of the using either the `Scripting.FileSystemObject` or the `ADODB.Stream` to open the file and read it contents into a variable. – user692942 Feb 24 '18 at 16:26

1 Answers1

-1

you can use create email body as HTML and

like

.............
body
.......

    <div><img src="linkOfImage" height="50px" width="50px"/></div>

......
...............

for this you have to set one bit in your email header.

Example:

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)

'  The mailman object is used for sending and receiving email.
set mailman = CreateObject("Chilkat_9_5_0.MailMan")

'  Any string argument automatically begins the 30-day trial.
success = mailman.UnlockComponent("30-day trial")
If (success <> 1) Then
    outFile.WriteLine(mailman.LastErrorText)
    WScript.Quit
End If

'  Set the SMTP server.
mailman.SmtpHost = "smtp.comcast.net"

'  Create a new email object
set email = CreateObject("Chilkat_9_5_0.Email")

'  Add an embedded image to the HTML email.
fileOnDisk = "images/dude2.gif"
filePathInHtml = "dudeAbc.gif"

'  Embed the GIF image in the email.
success = email.AddRelatedFile2(fileOnDisk,filePathInHtml)
If (success <> 1) Then
    outFile.WriteLine(mailman.LastErrorText)
    WScript.Quit
End If

'  The src attribute for the image tag is set to the filePathInHtml:
htmlBody = "<html><body>Embedded Image:<br><img src=""dudeAbc.gif""></body></html>"

'  Set the basic email stuff: HTML body, subject, "from", "to";
email.SetHtmlBody htmlBody
email.Subject = "VBScript HTML email with an embedded image."
success = email.AddTo("Admin","admin@chilkatsoft.com")
email.From = "Chilkat Support <support@chilkatsoft.com>"

success = mailman.SendEmail(email)
If (success <> 1) Then
    outFile.WriteLine(mailman.LastErrorText)
Else
    outFile.WriteLine("Mail Sent!")
End If


outFile.Close
Dupinder Singh
  • 7,175
  • 6
  • 37
  • 61