Mail from VB6 without MAPI
There are many ways to sent email from VB, and while it is quite possible to do it with the MAPI control, i found a much simpler way, using a webbrowser control and an ASP page. My code simply retrieves the to, from, subject and body information from the url. To use it, you just create an invisble web browser in the form, and then with a little string manipulation, you can navigate to the webbrowser with all the info necessary to send the email.
The page is on my site at www.startingqbasic.co.uk/aspmailer.asp.
To use it, add values for to=,from=,subject= and body= values to the url and there you go. I use this vb code:
VB Code:
Private Sub sendmailbutton_Click()
Dim mailurl As String
mailurl = "http://www.startingqbasic.co.uk/aspmailer.asp?"
' that line sets the start of the page string
mailurl = mailurl + "to=" + to_box.Text
'this adds the to details to the navigation string
mailurl = mailurl + "&" + "from=" + from_box.Text
'this adds the from details to the navigation string
mailurl = mailurl + "&" + "subject=" + subject_box.Text
'this adds the subject details to the navigation string
mailurl = mailurl + "&" + "body=" + body_box.Text
'this adds the subject details to the navigation string
mailbrowser.Navigate (mailurl)
'this navigates the webbrowser to the page
End Sub
And thats it. It's free, and if you would like the asp code for it, just email and ask.
KAZAR
Re: Mail from VB6 without MAPI
Thank u for this nice code. I am new to vb world. could u tell me how many text boxes do i need and what should i name them in order collect email ,subject ,... and submit button. I be happy if u help me out here.Furthermore, i be happy if u share the asp code with use.Thanks
Re: Mail from VB6 without MAPI
well, the asp code i use is:
Code:
<%
Dim tovar,fromvar,subjectvar,bodyvar,Mail
Set Mail=Server.CreateObject("CDONTS.NewMail")
tovar=request.querystring("to")
fromvar=request.querystring("from")
subjectvar=request.querystring("subject")
bodyvar=request.querystring("body")
Mail.To=tovar
Mail.From=fromvar
Mail.Subject=subjectvar
Mail.Body=bodyvar
Mail.Send
Set Mail=nothing
%>
Text boxes in vb can be called anything you like, as long as you insert their text at the right point in the url.
If you looked at the end url, it would look like:
http://www.startingqbasic.co.uk/[email protected]&[email protected]&subject=ASP Mailer&body=ASP Mailer Test
or something like that
if you want to use it in a web page, then just name the textboxes to, from, subject and body, and use the get method, not the post.
I hope that answers your question
Re: Mail from VB6 without MAPI
you could use the INet control also
Re: Mail from VB6 without MAPI
True, but it doesn't differ functionality.
You could have a sub that did this:
VB Code:
Sub sendmail()
Dim MailInet as INet
Dim mailurl As String
mailurl = "http://www.startingqbasic.co.uk/aspmailer.asp?"
' that line sets the start of the page string
mailurl = mailurl + "to=" + to_box.Text
'this adds the to details to the navigation string
mailurl = mailurl + "&" + "from=" + from_box.Text
'this adds the from details to the navigation string
mailurl = mailurl + "&" + "subject=" + subject_box.Text
'this adds the subject details to the navigation string
mailurl = mailurl + "&" + "body=" + body_box.Text
'this adds the body details to the navigation string
MailInet.OpenURL(mailurl)
'this opens the page with the dimmed inet control
End sub
That way you could just use it without having to create the INet Control First.
I must point out however that I have found computers with the Inet Control Missing for whatever reason, not so with the webbrowser control.
Re: Mail from VB6 without MAPI
Actually i have just been checking the inet control and it does work better.
The effect is the same, but, if you are looping the function, ie, sending lots of emails at once, then you have to make your program wait if you use the webbrowser control, not so with the INet.
So kudos and thanks to the182guy :thumb:
Re: Mail from VB6 without MAPI
Re: Mail from VB6 without MAPI
gooooooooooooooood maaaaaaaaaaaan
Re: Mail from VB6 without MAPI
thanks, tho this is a fairly old post. i still use this method tho.
Re: Mail from VB6 without MAPI
I want to send mail by VB6, but It have to use content of my programe and auto send after. can i help you?
Re: Mail from VB6 without MAPI
You have to use code like this:
VB Code:
Option Explicit
'''''''''''Notes on this sub'''''''''''
'At the moment you may only send text based data for the body argument, but eventually i will
'add a function to send HTML.
'
'The good thing about the inet control is that it hangs the thread until it has
'finished, which makes it ideal for looping.
'''''''''''''''''''''''''''''''''''''''
Sub SendMail(to_addr As String, from_addr As String, subject As String, data As String)
Dim MailInet As INet
Dim mailurl As String
mailurl = "http://www.startingqbasic.co.uk/aspmailer.asp?"
' that line sets the start of the page string
mailurl = mailurl + "to=" + to_addr
'this adds the to details to the navigation string
mailurl = mailurl + "&" + "from=" + from_addr
'this adds the from details to the navigation string
mailurl = mailurl + "&" + "subject=" + subject
'this adds the subject details to the navigation string
mailurl = mailurl + "&" + "body=" + data
'this adds the body details to the navigation string
MailInet.OpenURL (mailurl)
'this opens the page with the dimmed inet control
End Sub
Sub SendAllData()
'Lets say you have 4 listboxes - one containing the to email addresses, another one the
'from email addresses, another one the subject and one more, with the data you wish to send
Dim i As Integer
For i = 0 To to_listbox.ListCount - 1
SendMail to_listbox.List(i), from_listbox.List(i), subject_listbox.List(i), data_listbox.List(i)
Next i
'so, for each item in the listboxes (assuming the same number in each), then all the data in the listboxes
'will be sent to the corresponding addresses.
'note, there is a limit on how much data can be sent. the advanced ones among you know that you can post data
'using winsock headers. soon i will add a post function as well, which means that there is no limit
End Sub
Re: Mail from VB6 without MAPI
Thanks a lot ~-=~-= KAZAR =-~=-~
Re: Mail from VB6 without MAPI
I know this is preety old
but how would one use the asp page >>?
I mean where do I put it in my server!!??
Code:
<%
Dim tovar,fromvar,subjectvar,bodyvar,Mail
Set Mail=Server.CreateObject("CDONTS.NewMail")
tovar=request.querystring("to")
fromvar=request.querystring("from")
subjectvar=request.querystring("subject")
bodyvar=request.querystring("body")
Mail.To=tovar
Mail.From=fromvar
Mail.Subject=subjectvar
Mail.Body=bodyvar
Mail.Send
Set Mail=nothing
%>
Re: Mail from VB6 without MAPI
Hello I been waiting days now /
Anyways I learn my host don't support ASP .. Or SMTP on my plan anyways ..
So any ideas on how to do it in PHP 4.x.x & So it don't need the local SMTP .. So it can remote ..
O yes the mail() is disabled as well in PHP lol
I want it so its like that below .. I mean so u can use it in VB still !!!
Okays :eek2:
Re: Mail from VB6 without MAPI
Well, sorry for the lack of reply, but i have been on holiday.
If you want to send the email from vb then you don't need to put it on your server. Just use my server's url. To use it online, then i shall add a thing so that you can attach a url to forward to after completing the mail send. Anyway, what kind of crap server doesn't have ASP, or php mailing on it?
Re: Mail from VB6 without MAPI
My host is http://awardspace.com }~
& I'm on the free plan so I don't get the Mail() PHP funtion Or SMTP ..
O an there still in beta so they don't support ASP yet I guess .
& thx
Re: Mail from VB6 without MAPI
Hello you need to fix this lol .
http://www.startingqbasic.co.uk/aspmailer.asp
Code:
Microsoft VBScript compilation error '800a03f2'
Expected identifier
/aspmailer.asp, line 42
Upload.
-------^
Re: Mail from VB6 without MAPI
sorry i was working on it. it's fixed
Re: Mail from VB6 without MAPI
Re: Mail from VB6 without MAPI
Nothing, but i had updated it, but had missed something
Re: Mail from VB6 without MAPI
Ohh . What you update >
?
Re: Mail from VB6 without MAPI
I was adding an attachment function, but it isn't finished yet. Still got some bugs to iron out.