Alpha Video Training
Results 1 to 7 of 7

Thread: Xbasic Check (if then) when using .NET email?

  1. #1
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Xbasic Check (if then) when using .NET email?

    The normal way of emailing with Xbasic doesn't work for me. Even when I use the "send email" helper function in a grid I must check the .NET option or I can't get an email to send through our LAN.
    I need to check to make sure it's working in my Xbasic code but I'm not sure how to do it as when try this:
    Code:
    if MailClient.Send(msg) Then
    ...
    I get an invalid variable type 'Z'...can't be used with condition.

    Otherwise it's working and sending an email, I just need to error proof the deal.

    Is there a way to check if a .NET email is working properly within the Xbasic code?

  2. #2
    Member
    Real Name
    Dave
    Join Date
    Jul 2012
    Location
    Southern California
    Posts
    621

    Default Re: Xbasic Check (if then) when using .NET email?

    The variable type "Z' is a NULL value/variable. Can I see more of the code? How did you define MailClient?

    FYI - I am able to use the .Net Mail::SmtpClient, email_send_noprofile(), and email_smtp_send().

  3. #3
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: Xbasic Check (if then) when using .NET email?

    Hi Dave,

    I'll post some code when I fire up my dev computer again....which may not be until Monday (god willing) so check back. I appreciate the help!

  4. #4
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: Xbasic Check (if then) when using .NET email?

    Well, I didn't make it even one day without being in front of my computer so here is a snippit of the code that sends an email.
    I really would just need to send an error message if it doesn't send but at this point I don't know where to check that it has sended



    Code:
    dim recipient as c = rs.Data("emailaddress")	
    					dim subj as C = "Completed Tool Request"
    					dim body as C = "Hello "+firstname+","+crlf()+crlf()+"A tool request (Number: "+ trnum +" ) that was approved by you has been checked as completed."+crlf()+crlf()+"Please check with the Manufacturing Engineering department if you have any questions."
    					dim ishtml as L = .F.
    					dim CC as C = "email@email.com"
    					dim CC2 as C = "email2@email.com"
    					dim sender as C = "NoReply@email.com"
    					dim EmailPassword as C = "password"
    					dim msg as System::Net::Mail::MailMessage = new System::Net::Mail::MailMessage()
    					msg.To.Add(recipient)
    						msg.From = new System::Net::Mail::MailAddress(sender)
    						msg.Subject = subj
    						msg.Body = body
    						msg.BodyEncoding = System::Text::Encoding::UTF8
    						msg.Priority = System::Net::Mail::MailPriority::Normal
    					dim addrCC as System::Net::Mail::MailAddress = new System::Net::Mail::MailAddress(CC)
    					dim addrCC2 as System::Net::Mail::MailAddress = new System::Net::Mail::MailAddress(CC2)
    					msg.CC.Add(addrCC)
    					msg.CC.Add(addrCC2)
    					dim MailClient as System::Net::Mail::SmtpClient = new System::Net::Mail::SmtpClient("email.email.com",25)
    					MailClient.EnableSsl = .F.
    					MailClient.UseDefaultCredentials = .T.
    					MailClient.Send(msg)
    					vjscmd = "alert('An email to the approver of this tool request has been sent telling them that it has been completed.');"
    					msg.Dispose()

  5. #5
    Member
    Real Name
    Dave
    Join Date
    Jul 2012
    Location
    Southern California
    Posts
    621

    Default Re: Xbasic Check (if then) when using .NET email?

    If your mail server requires a user ID and password, you will need to set "MailClient.UseDefaultCredentials = .f." and on the very next line add:

    Code:
    MailClient.Credentials = new System::Net::NetworkCredential(EmailUserid, EmailPassword)
    MailClient.Send() does not return an error result. That's why you were getting the error message. I too was stumped a couple months ago on how to be sure the email was sent. You need to use the "on error" statement just before instantiating the SmtpClient in order to check for .Net exceptions:

    Code:
    on error goto Error_Handler
        dim MailClient as System::Net::Mail::SmtpClient = new System::Net::Mail::SmtpClient("email.email.com",25)
        MailClient.EnableSsl = .F.
        MailClient.UseDefaultCredentials = .T.
        MailClient.Send(msg)
        vjscmd = "alert('An email to the approver of this tool request has been sent telling them that it has been completed.');"
        msg.Dispose()
    
        . . .
    
        return
    
    Error_Handler:
        ErrorCode = error_code_get()
        ErrorLine = error_line_number_get()
        ErrorMessage = error_text_get()
        msg.Dispose() 
    
        . . .
    
    (end of function)
    You can test the error handler by using an invalid smtp server name or port number. All of the "error_" functions are optional of course.

    Hope this helps.
    Last edited by DaveF; 03-09-2013 at 05:37 PM.

  6. #6
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: Xbasic Check (if then) when using .NET email?

    Hi Dave,
    I won't be able to do any testing until I go to work tomorrow; however, I do want to reiterate that my code does work to send an email. I must admit I don't really understand most of it yet as I copied it out of the alpha wiki. I guessed that the "default credentials" were what I placed in my web project properties. If this is the case, then I don't even need the line specifying them right?

    Anyway, thanks for the error handler code. I'll give it a try on Monday!

  7. #7
    Member
    Real Name
    Dave
    Join Date
    Jul 2012
    Location
    Southern California
    Posts
    621

    Default Re: Xbasic Check (if then) when using .NET email?

    As long as you don't attempt to check for a return code using an "if" statement after calling "MailClient.Send()", it will work just fine except you won't know if the email was sent successfully. You need to instead use "on error" to catch any .NET exceptions. The reason I mentioned the "default credentials" was just in case you ever switch to an SMTP server that requires authentication.

Similar Threads

  1. Help translating vb.net to xbasic
    By gatorfans99 in forum Alpha Five Version 11 - Desktop Applications
    Replies: 8
    Last Post: 06-29-2012, 02:58 PM
  2. Help translating vb.net to xbasic
    By mrft0 in forum Alpha Five Version 11 - Desktop Applications
    Replies: 4
    Last Post: 06-15-2012, 04:44 PM
  3. email with net mailer
    By gwsgreg in forum Alpha Five Version 10 - Desktop Applications
    Replies: 0
    Last Post: 11-26-2009, 12:23 PM
  4. Xbasic with .NET DLLs
    By emathias in forum Alpha Five Version 8
    Replies: 3
    Last Post: 09-06-2007, 06:13 PM
  5. Xbasic and Raw Net I/O
    By KeithW in forum Alpha Five Version 6
    Replies: 10
    Last Post: 11-17-2004, 08:28 AM

Bookmarks

Posting Permissions

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