It does work!

  • 19 years ago

    ok... THERE MUST BE A WAY TO DO THIS!!


    I want to send an email with the data I want inside it, and not have the user do a thing.




    Say the user clicks a button. I want text1.text to go in an e-mail and address it, and send it.




    Please HELP ME!!!

  • 19 years ago

    This is a copy of a code snippet from a program I wrote a long time ago.


    It reads a file to get the names of who to send the message to, then sends a text file to the person(s) in the list


    to make it work


    Sub Command1_click()


          MailIt


    End Sub




    Sub mailIt()


       Dim msgtext As String


       Dim i, tmp(10)


       


       Dim index As Variant


       readReadMe msgtext


       getMailRecipients tmp(), index


       With frmMain


          .MapiSess.DownLoadMail = False


          .MapiSess.Action = mapSignOn


          .List1.AddItem "Logging on to Mail Server"


          .List1.ListIndex = .List1.ListCount - 1


          .MapiMess.SessionID = .MapiSess.SessionID


          For i = 1 To index


               .MapiMess.Action = mapCompose


               .MapiMess.MsgNoteText = msgtext


               .MapiMess.RecipAddress = tmp(i)


               .MapiMess.Action = mapSend


          Next


          .List1.AddItem "Completed mail message"


          .MapiSess.Action = mapSignOff


          .List1.AddItem "Mail sent."


          .List1.ListIndex = .List1.ListCount - 1


       End With


    End Sub




    Sub getMailRecipients(s(), m)


       Dim i, j, x


       Dim a$, tmp


       i = FreeFile


       


       Open "\fiche\mail_recipients.txt" For Input As i


       x = 0


       Do While Not EOF(i)


          Line Input #i, a$


          x = x + 1


          s(x) = a$


         


       Loop


       m = x


       If m = 0 Then


          GoTo bad_inputfile


       End If


       Exit Sub


    bad_inputfile:


       MsgBox "Cannot send mail. MAIL_RECPIENTS.TXT has no adressees.", vbOKOnly


    End Sub

  • 19 years ago

    I would be grateful if you could email the program to [email protected]


    THANK YOU!!

  • 19 years ago

    try this.  


    Dim ol As New Outlook.Application


    Dim mi As Outlook.MailItem




    Set mi = ol.CreateItem(olMailItem)




    With mi


      .To = Combo1.Text (or whoever you want to send it to)


      .Subject = "(the subject)"


      .Attachments.Add "(filename of any attachment you want to add)"


     


      .Body = "( You could add the contents of a textbox etc..  to be the body of the text)"


      .Send


    End With




    Set mi = Nothing


    ol.Quit


    Set ol = Nothing






    Tony

  • 19 years ago

    i was try it but it give error at 'new outlook.application'


    please help me


    okay

  • 19 years ago

    To get the code above to work you have to add a reference to Microsoft Outlook.


    Select 'Project - References' from the menu bar and select 'Outlook 98 Type Library' (or similar if you use another version of outlook). From now on the code will work.


    Good luck!

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There's no test like production” - Anon