Results 1 to 28 of 28

Thread: E-Mail in VB

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 1999
    Posts
    23

    Post

    I'm trying to make a program where all the user has to enter is the e-mail address to send the e-mail, the subject, and the message and it will send the e-mail with no problem.

    Can anyone help me with this?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    If you don't mind the User Pressing the Send Button you could launch the Default Mail Client using the ShellExecute API passing the Email, Subject and Message in the Command Line.

    Otherwise you could use the Winsock Control to Access a Mail Server Directly, eg.

    For this example you'll need a Winsock Control, Command Button and several Textboxes..
    Code:
    Private Sub cmdSend_Click()
        Caption = "Sending Message.."
        If Winsock1.State <> sckClosed Then Winsock1.Close
        Winsock1.Connect "Some.MailServer.com", 25
    End Sub
    
    Private Sub Winsock1_Connect()
        Winsock1.SendData "HELO " & Winsock1.LocalIP & vbCrLf & _
        "MAIL FROM: <[email protected]>" & vbCrLf & _
        "RCPT TO: <" & txtTo & ">" & vbCrLf & _
        "DATA" & vbCrLf & _
        "TO: " & txtTo & vbCrLf & _
        "FROM: <[email protected]>" & vbCrLf & _
        "SUBJECT: " & txtSubject & vbCrLf & _
        txtMsg & vbCrLf & "." & vbCrLf & _
        "QUIT" & vbCrLf
    End Sub
    
    Private Sub Winsock1_SendComplete()
        Caption = "Send Complete."
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 1999
    Posts
    23

    Post

    How would I connect to lets say...a Mailcity account to send the E-mail?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 1999
    Posts
    23

    Post

    What i'm trying to do is make my program send the e-mail as a WWWPager to my icq. I know where to send it but what would I put for the mail server?

  5. #5
    New Member
    Join Date
    Oct 1999
    Posts
    2

    Post

    The subprogram below utilizes a MAPI Session and MAPIMessage control from the MS MAPI 6.0 controls to send a message. It automatically opens the default email client (in the background) and sends a message using the specified information. It works well, I have used it in VB and in MS Access apps.


    Private Sub SendEmail()
    MAPISession1.SignOn
    MAPIMessages1.SessionID = Me.MAPISession1.SessionID
    MAPIMessages1.Compose
    MAPIMessages1.MsgSubject = "Hey Hey"
    MAPIMessages1.MsgNoteText = "This is the body of my email"
    MAPIMessages1.RecipAddress = "[email protected]"
    MAPIMessages1.Send
    MAPISession1.SignOff
    End Sub

  6. #6
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    Hi, Morpheus.

    Your code doesn't work for me: when it reaches the line "MAPIMessages1.Send" I get error 32002 "error not specified". Is there anything wrong in the code? Am I missing something? Please, help! I need to be able to send e-mails automatically!

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Post

    You also have to set the RecipDisplayName property:
    MAPIMessages1.RecipDisplayName = MAPIMessages1.RecipAddress ' Or "John Doe" or whatever

    Good luck!


    ------------------
    Joacim Andersson
    [email protected]
    [email protected]
    www.YellowBlazer.com



  8. #8
    New Member
    Join Date
    Oct 1999
    Posts
    2

    Post

    Joacim is right, you need to set the recipient display name. Thanks Joacim.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 1999
    Posts
    23

    Post

    Whay if the person doesn't have a default e-mail program on their computer?

  10. #10
    New Member
    Join Date
    Feb 1999
    Posts
    10

    Post

    Juan Carlos

    Try Send True
    or Send False

    That should make it work.

  11. #11
    Member
    Join Date
    May 1999
    Location
    St. Louis, MO, USA
    Posts
    54

    Post

    I think the above code is woderfull for my app however could someone please explain why my e-mail is not getting delivered. This Is the message I'm getting.
    No transport provider was available for delivery to this recipient.
    Also, what is ment by setting send = true?
    Is that my line of code? send = true What does it do?

  12. #12
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: E-Mail in VB

    why not use cdo, see the code i use, just make reference to the cdo library

    vb Code:
    1. Public Function SendMail(sTo As String, sSubject As String, sFrom As String, _
    2.     sBody As String, sSmtpServer As String, iSmtpPort As Integer, _
    3.     sSmtpUser As String, sSmtpPword As String, _
    4. sFilePath as string, bSmtpSSL As Boolean) As String
    5.    
    6.     On Error GoTo SendMail_Error:
    7.    
    8.     Dim lobj_cdomsg      As CDO.Message
    9.     Set lobj_cdomsg = New CDO.Message
    10.     lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = sSmtpServer
    11.     lobj_cdomsg.Configuration.Fields(cdoSMTPServerPort) = iSmtpPort
    12.     lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL
    13.     lobj_cdomsg.Configuration.Fields(cdoSMTPAuthenticate) = 1
    14.     lobj_cdomsg.Configuration.Fields(cdoSendUserName) = sSmtpUser
    15.     lobj_cdomsg.Configuration.Fields(cdoSendPassword) = sSmtpPword
    16.     lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 30
    17.     lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = 2
    18.     lobj_cdomsg.Configuration.Fields.Update
    19.     lobj_cdomsg.To = sTo
    20.     lobj_cdomsg.From = sFrom
    21.     lobj_cdomsg.Subject = sSubject
    22.     lobj_cdomsg.TextBody = sBody
    23.     lobj_cdomsg.AddAttachment (sFilePath)
    24.     lobj_cdomsg.Send
    25.     Set lobj_cdomsg = Nothing
    26.     SendMail = "ok"
    27.     Exit Function
    28. SendMail_Error:
    29.     SendMail = Err.Description
    30. End Function
    Last edited by coolcurrent4u; Apr 13th, 2011 at 04:58 AM.
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  13. #13
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: E-Mail in VB

    @ coolcurrent4u,

    While I am sure your post is helpful to someone please check the date of the last post before replying to a thread. This thread had been dead for 11 years before you replied to it.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  14. #14
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: E-Mail in VB

    Quote Originally Posted by Nightwalker83 View Post
    @ coolcurrent4u,

    While I am sure your post is helpful to someone please check the date of the last post before replying to a thread. This thread had been dead for 11 years before you replied to it.
    Officially it is not resolved

  15. #15
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: E-Mail in VB

    @Nightwalker83,

    I didn't realized the date. My bad!
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  16. #16
    Lively Member bren0098's Avatar
    Join Date
    Jul 2005
    Posts
    67

    Re: E-Mail in VB

    It helped me today! Mail rules have changed since 1999, but it's still a valid question.

  17. #17
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: E-Mail in VB

    Hey, Cool:

    I've tried using code like this before, and never been successful.

    What kind of values should I be feeding into the function, for example in the "server" and "port" fields, if I want to send through g mail?

    Thanks!

    vBryce

  18. #18
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: E-Mail in VB

    if using google,
    server = smtp.gmail.com
    [email protected]
    password=your password
    port=465

    NOTE
    make sure you enable smtp & pop in gmail under your account settings
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  19. #19
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: E-Mail in VB

    Thanks, I'll give that a whirl!

  20. #20
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: E-Mail in VB

    "The transport failed to connect to the server."

    This is the error message I get.

    I used the settings you suggested in the earlier post, and attempted to enable both POP and SMTP in my g mail account, but I was a little unsure how to do that. I think I got the POP enabled, but didn't see where to enable SMTP. Can you point me to where that is done more specifically? Thanks again!

  21. #21
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: E-Mail in VB

    make sure you set bSmtpSSL value to true

    Code:
    lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL
    How are you using the function
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  22. #22
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: E-Mail in VB

    Cool,

    I have that value set to "true."

    I am using your cdo code, and calling is using parameters from text boxes. I have stepped through it to verify that I like the values that I'm feeding into it.

    I'm stumped!

    Bryce

  23. #23
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: E-Mail in VB

    if you project is not big, attache it or the code you are using
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  24. #24
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: E-Mail in VB

    Hopefully this isn't a duplicate response. I tried to reply earlier, and it appears I wasn't successful.

    Anyway, attached is my form.

    Thanks!
    Attached Files Attached Files

  25. #25
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: E-Mail in VB

    i made an example, please check here
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  26. #26
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: E-Mail in VB

    Cool,

    Thanks for whipping that sample up.

    I attached a shot of what values I'm inputting, and the resulting issue I still have.

    Scratching my head!

    Bryce
    Attached Images Attached Images  

  27. #27
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: E-Mail in VB

    Possible causes
    • slow internet connection
    • Firewall blocking you from sending mail with that port/domain/Ip of gmail
    • Server is rejecting your account from sending email

    Possible solution
    • increase the timeout settings, the default is 30 seconds, change it to 60 or whatever you like
      vb Code:
      1. .Configuration.Fields(cdoSMTPConnectionTimeout) = 30 'change to 60
    • check you firewall and make sure it is not restricting the port/domain/Ip gmail
    • if possible create a new gmail/aol/gmx account and try again
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  28. #28
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: E-Mail in VB

    Cool,

    Thanks again for all your help!

    I'm thinking it must be my firewall, because the error message comes back relatively quickly regardless of how long I set the timeout for.

    I'm going to try it on a different machine (with different firewall settings that I can actually adjust!).

    Thanks!

    Bryce

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width