I am trying to send an email via Outlook from within a VB6 program. Everything is working fine so far, and my emails get sent successfully. I would like to send the recipient a link in the body of the email, however, that sends them to a network directory. I can't seem to get a hyperlink in the body of the email.
My code for sending the email thus far looks like this:
Dim outlookApp As Outlook.Application
Dim resultsEmail As Outlook.MailItem
Set outlookApp = CreateObject("Outlook.Application")
Set resultsEmail = Outlook.CreateItem(olMailItem)
With resultsEmail
.To = addressee
.Subject = emailSubject
.Body = "Results are available here: " & 'somehow put in a hyperlink
.Send
End With
addressee and emailSubject are just strings created earlier in the code.
I tried inserting an HTML link using VB6's horrific quote escapes, hoping Outlook would magically sort it out:
"<a href" & ch=" & chr(34) & "directoryLocation" & chr(34) & ">Link text</a>"
But it doesn't create the hyperlink, it just puts the resulting text in the body of the email:
Link text
How can I get a link in the generated email?
Looks like I found the answer and it was deceptively simple. Instead of using .body, I needed to insert the HTML link as I posted and use .HTMLBody instead:
With resultsEmail
.To = addressee
.Subject = emailSubject
.HTMLBody = "Results are available here: " & _
"<a href" & ch=" & chr(34) & "directoryLocation" & chr(34) & ">Link text</a>"
.Send
End With
Related
I am developing a script to send an email according to certain inputs, I am able to craft the email but not send it using the .Send method.
I am getting the following error: (please note that the line is matching the .Send use in the original case)
I have already successfully sent emails using the .SendKeys(^~) method, but I would like to be use Outlook object to do so and not simply send shortcuts.
This is my current code:
' Declare all variables that will be used later on
Dim outobj, mailobj, emailto, cc, subject, body, attachement
Dim strFileText
Dim objFileToRead
Dim splitEmailto
' Set the outlook application object
Set outobj = CreateObject("Outlook.Application")
' set the namespace
Set myNamespace = outobj.GetNameSpace("MAPI")
msgbox myNamespace.Folders(2)
' Set the mail item object
Set mailobj = outobj.CreateItem(olMailItem)
' Set a shell
Set WshShell = WScript.CreateObject("WScript.shell")
' Get all the argument and assign
emailto = "name#domain.eu"
cc = "name#domain.eu"
subject = "Simple Email"
body = "Some Text"
attachement = "C:\Users\name\Desktop\fileName.xls"
' Craft the email object
With mailobj
.Display
' assign the tos
.To = cstr(emailto)
' add CCs
.CC = cstr(cc)
' attach the relevant files
If attachement <> "" Then
If instr(attachement, ";") Then
splitAtt = split(attachement, ";")
For Each att In splitAtt
If att <> "" Then
.Attachments.add cstr(att)
End If
Next
Else
.Attachments.add cstr(attachement)
End If
End If
If Subject <> "" Then
.Subject = Subject ' sets the subject
End If
If body <> "" Then
.Body = body ' sets the body
End If
.Send
End With
' Clear the memory
Set outobj = Nothing
Set mailobj = Nothing
' check for no more events in the sending event
' Report out & Quits
WScript.StdOut.WriteLine("Email sent")
WScript.Quit
I would like to be able to send the email with the .Send. any idea?
The error is E_ABORT.
Why are you displaying the message and immediately calling Send? You either display the message (Display, but no Send), or just send it outwith displaying (Send, but no Display).
OK so I have a script that goes through my outlook inbox looking for a particular header string. This works great for emails directly in my inbox. Now I'm trying to expand this detection to emails that contain other emails as attachments. I've spent significant time researching this and I can't seem to find the proper way to access the email attachment directly. What I've ended up doing is saving the attachment to disc and then reading it back in using CreateItemFromTemplate. I find this to be a cludge solution and I'm hoping someone here can help me find a more elegant way to do this where I can bypass the saveas as CreateItemFromTemplate and directly create an item object from the attachment. Here is proof of concept script I've put together for this:
Const olFolderInbox = 6
Const olMail = 43
Const olEmbeddeditem = 5
Const PropName = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
Set app = CreateObject("Outlook.Application")
set objNamespace = app.GetNamespace("MAPI")
set objInboxItems = objNameSpace.GetDefaultFolder(olFolderInbox).items
wscript.echo "Have your inbox open checking for fish tests or emails as attachments"
for each objItem in objInboxItems
if objItem.Class = olMail then
with objItem
strHeader = .PropertyAccessor.GetProperty(PropName)
iLoc1 = instr(1,strHeader,"X-Testing",1)
if iLoc1 > 0 then
wscript.echo "mytest. From: " & .Sender & " at: " & .ReceivedTime & " subjet: " & .Subject
end if
iLoc1 = instr(1,strHeader,"X-PHISHTEST",1)
if iLoc1 > 0 then
wscript.echo "Go Fish. From: " & .Sender & " at: " & .ReceivedTime & " subjet: " & .Subject
end if
if .attachments.count > 0 then
set objAttachment = .attachments.item(1)
if objAttachment.type = olEmbeddeditem then
wscript.echo "Has Attachment. From: " & .Sender & " at: " & .ReceivedTime & " subjet: " & .Subject
wscript.echo " - Filename: " & objAttachment.Filename
objAttachment.SaveAsFile ("c:\temp\TempEmail.msg")
set objExtMsg = app.CreateItemFromTemplate("c:\temp\TempEmail.msg")
strExtHeader = objExtMsg.PropertyAccessor.GetProperty(PropName)
iLoc1 = instr(1,strExtHeader,"X-Testing",1)
if iLoc1 > 0 then wscript.echo " ++ This is a plain test message"
end if
end if
end with
end if
next
wscript.echo "That's all folks" `
That is the best you can do in OOM alone - save the attachment as an MSG file and then reopen it. OpenSharedItem is a better way to open an MSG file than CreateItemFromTemplate.
On the Extended MAPI level (C++ or Delphi), you can open the PR_ATTACH_DATA_OBJ property as IMessage using IAttach::OpenProperty. If Extended MAPI is not an option, you can use Redemption (I am its author - any language) - both Safe*Item and RDO families of objects expose EmbeddedMsg property on the attachment object that return the attachment message.
I have written code using asp classic and vb-script in payment.asp. i am posting data to 3rd party using winhttprequest and its submitting successfully and it works fine but my issue is:
after posting data, on 3rd party page, there is creating a unique ID which i want to retrieve on same page payment.asp
how can i retrieve unique ID created by 3rd party.
My code is as below given:
<%
Dim http, url, data
Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
url = "https://www.instamojo.com/api/1.1/payment-requests/"
data = "amount=" & amount & "&buyer_name=" & buyer_name & "&purpose=" & purpose & "&redirect_url=" & redirect_url & "&phone=" & phone & "&send_email=" & send_email & "&send_sms=" & send_sms & "&email=" & email & ""
With http
Call .Open("POST", url, False)
Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call .SetRequestHeader("X-Api-Key", "[X-Api-Key]")
Call .SetRequestHeader("X-Auth-Token", "[X-Auth-Token]")
Call .Send(data)
End With
If http.Status = 201 Then
Call Response.Write("succeeded: " & http.Status & " " & http.StatusText)
Else
Call Response.Write("Server returned: " & http.Status & " " & http.StatusText)
End If
%>
please help me.
Apparently the API's results are formatted in JSON. So you'll need a JSON parser like ASPJSON.
Include the aspJSON1.17.asp in your payment.asp and
after getting the response with 201 status code, parse the ID like this:
Set oJSON = New aspJSON
oJSON.loadJSON http.ResponseText
Response.Write oJSON.data("payment_request")("id")
Hi I am sending lotus notes mail with VB script . Now I want to send mail with other mail box which is opened in my lotus notes instead of my mail box. I tried different options but no luck. I am using below code to send mail.
You can find the code in below URL:
https://gallery.technet.microsoft.com/scriptcenter/fe141119-9599-46a7-90ca-8dbc66d50297
option explicit
' --------------------------------------------------------------------------
' -- Create Lotus Notes email (and add attachment) using VB Script
' --
' -- Version 1.01
' --
' -- Created by : Michael Green
' -- migreen#westpac.com.au
' --
' -- Based on in-complete/partially working script from :
' -- http://en.allexperts.com/q/Using-Lotus-Notes-1427/Creating-LotusNotes-email-using-1.htm
' --
' -- Created : 06/10/2009
' -- Last Updated: 07/10/2009
' --------------------------------------------------------------------------
Dim oSession ' AS NotesSession
Dim strServer
Dim strUserName
Dim strMailDbName
Dim oCurrentMailDb ' as NOTESDATABASE
Dim oMailDoc ' as NOTESDOCUMENT
Dim ortItem ' as NOTESRICHTEXTITEM
Dim ortAttacment ' as NOTESRICHTEXTITEM
Dim oEmbedObject ' as ????
dim cstrAttachment
Dim blAttachment
cstrAttachment = "c:\Temp\Telstra.xls"
blAttachment = True
' Start a session to notes
wscript.echo "## Connecting to Lotus Notes session..."
Set oSession = CreateObject("Notes.NotesSession")
wscript.echo("NotesVersion : " & oSession.NotesVersion)
wscript.echo("NotesBuildVersion: " & oSession.NotesBuildVersion)
wscript.echo("UserName : " & oSession.UserName)
wscript.echo("EffectiveUserName: " & oSession.EffectiveUserName)
wscript.echo "## GetEnvironmentString..."
strServer = oSession.GetEnvironmentString("MailServer",True)
wscript.echo("Server :" & strServer)
' eg. CN=Michael V Green/OU=CORPAU/OU=WBCAU/O=WBG
strUserName = oSession.UserName
strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf"
wscript.echo("MailDbName :" & strMailDbName)
wscript.echo "## Getting current Notes database..."
' open the mail database in Notes
set oCurrentMailDb = oSession.CurrentDatabase
wscript.echo("fileName:" & oCurrentMailDb.fileName)
wscript.echo("filePath:" & oCurrentMailDb.filePath)
wscript.echo("server:" & oCurrentMailDb.server)
wscript.echo("Title:" & oCurrentMailDb.Title)
If oCurrentMailDb.IsOpen = True Then
' Already open for mail
wscript.echo "## Lotus Notes mail database is already open !"
Else
wscript.echo "## Opening Lotus Notes mail database..."
oCurrentMailDb.OPENMAIL
End If
' Create a document in the back end
Set oMailDoc = oCurrentMailDb.CREATEDOCUMENT
' Set the form name to memo
OMailDoc.form = "Memo"
with oMailDoc
.SendTo = "migreen#westpac.com.au"
.BlindCopyTo = "mgreen#ozemail.com.au"
.CopyTo = "migreen#westpac.com.au"
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
set ortItem = oMaildoc.CREATERICHTEXTITEM("Body")
with ortItem
.AppendText("Test of RTF Item append")
.AddNewLine(2)
.AppendText("Signature")
End With
' Create additional Rich Text item and attach it
If blAttachment Then
Set ortAttacment = oMailDoc.CREATERICHTEXTITEM("Attachment")
' Function EMBEDOBJECT(ByVal TYPE As Short, ByVal CLASS As String, ByVal SOURCE As String, Optional ByVal OBJECTNAME As Object = Nothing) As Object
' Member of lotus.NOTESRICHTEXTITEM
Set oEmbedObject = ortAttacment.EMBEDOBJECT(1454, "", cstrAttachment, "Attachment")
End If
wscript.echo "## Sending email..."
with oMailDoc
.PostedDate = Now()
.SAVEMESSAGEONSEND = "True"
.send(false)
end with
wscript.echo "## Sent !"
' close objects
set oMailDoc = nothing
set oCurrentMailDb = nothing
set oSession = nothing
Just replace the lines (that are complete nonsense, but I told you in the other post):
strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf"
wscript.echo("MailDbName :" & strMailDbName)
wscript.echo "## Getting current Notes database..."
' open the mail database in Notes
set oCurrentMailDb = oSession.CurrentDatabase
wscript.echo("fileName:" & oCurrentMailDb.fileName)
wscript.echo("filePath:" & oCurrentMailDb.filePath)
wscript.echo("server:" & oCurrentMailDb.server)
wscript.echo("Title:" & oCurrentMailDb.Title)
If oCurrentMailDb.IsOpen = True Then
' Already open for mail
wscript.echo "## Lotus Notes mail database is already open !"
Else
wscript.echo "## Opening Lotus Notes mail database..."
oCurrentMailDb.OPENMAIL
End If
with
strServer = "ServerNameWhereMailboxIs"
strMailDbName = "mail\nameofotherdatabase.nsf"
set oCurrentMailDb = oSession.GetDatabase( strServer, strMailDbName )
That will do the trick.
As your question changed after my answer, I will -for the sake of anybody finding this question in the future- add some code for "sending an email in the name of another sender":
In Lotus Notes it is not possible to "send" a mail without leaving traces of the person who really sent it:
When you receive such a mail, that was sent by someone else you will see, that the mail comes from the other mailbox, but it will contain the information "Sent by" with the mailaddress of the "real" sender.
To at least make the "visual" sender look right, you need to add different fields that are needed in different cases: These fields are Principal, InetPrincipal, From and InetFrom.
However: On a Domino- Server that is configured right, this will not help: It will calculate these fields from the "real" sender and ignore what you gave him.
But there is a trick to make the router leave these fields alone: You have to add the NotesDomain to the adressen. If you add the following lines to your code, then the router will ignore these and keep the fields intact:
MailDoc.principal = "noreply#company.com#NotesDomain"
MailDoc.inetprincipal = "noreply#company.com#NotesDomain"
MailDoc.from = "noreply#company.com#NotesDomain"
MailDoc.inetfrom = "noreply#company.com#NotesDomain"
If you really need to "hide" the real sender completely from the recipient, then you cannot create the mail in the mail database, but create it directly in the "mail.box" of the server and just "Save" it instead of "Send" it. But this has other downsides and will not be discussed here.
I just want to leave one more answer about "send from/reply to" because this question here is what I found when I was searching for help:
I found out that only my own mailadress is shown to external recipients or people not using IBM notes. Even if I sent mails via a different mailfile (a Mail-In) only my own mailadress was shown and I also was the one the recipient could reply to. So I tried something, and it worked.
After some testing, this lines helped me out internal and external:
sender = """John Doe""" & "<support#domain.de>"
MailDoc.ReplyTo = sender
MailDoc.SMTPOriginator = sender
MailDoc.sender = sender
MailDoc.principal = sender
MailDoc.inetprincipal = sender
MailDoc.from = sender
MailDoc.inetfrom = sender
MailDoc.displayfrom = sender
I'm trying to send an email with VB script/ASP (I don't normally use this language but this is what the site is built in), and it is throwing a 500 error.
I'm not seeing what I did wrong. Everything looks like it should execute to me. Any ideas?
<%
dim name
dim from
dim company
dim phone
dim zip
dim message
dim areas
name = Request.Form("name")
from = Request.Form("from")
company = Request.Form("company")
phone = Request.Form("phone")
zip = Request.Form("zip")
areas = Request.Form("areas")
message = Request.Form("message")
Dim Mail, strHost
Dim strSubject, strBody, strPath
strHost = "localhost"
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = strHost
Mail.From = "cphelps#client.com"
Mail.FromName = "Client Name"
Mail.AddAddress "cphelps#client.com"
If Not InStr(from, "domain.com") Then Mail.AddBcc "cphelps#client.com"
Mail.Subject = name & " sent a request"
Mail.Body = name & "," & vbCrLf & vbCrLf &_
"Name:" & name & vbCrLf &_
"Company: " & company & vbCrLf &_
"From: " & from & vbCrLf &_
"Phone: " & phone & vbCrLf &_
"Zip Code: " & zip & vbCrLf &_
"Message: " & message & vbCrLf &_
Mail.Send
Response.Redirect("jlg_thank_you.asp")
set Mail = nothing
%>
The first thing I noticed is that you are missing an End If in the code sample provided.
I disabled Friendly error messages and I attempted to run the code and got this error:
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/test.asp, line 26
800401f3
On researching this error I found someone with a similar problem:
Server.createObject with Persist.Mailsender error
They suggested that its a missing dll problem.
For my projects I have used Server.CreateObject("CDO.Message")
Here is an example of my code:
Set mail = Server.CreateObject("CDO.Message")
mail.To = varTo
mail.From = varFrom
mail.Subject = varSubject
mail.HTMLBody = varBody
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.domain.com"
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
mail.Configuration.Fields.Update
mail.Send
Make sure you downloaded the latest version of ASPEmail and that it is present on the server running the script.
Also, register it using this command line:
regsvr32 c:\path\aspemail.dll