Differences between revisions 1 and 2
Revision 1 as of 2009-06-16 12:41:27
Size: 58
Editor: SimonMarsden
Comment:
Revision 2 as of 2009-06-16 13:18:44
Size: 2190
Editor: SimonMarsden
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Page under construction The following code shows how to send an e-mail using the .NET System.Mail namespace. The code is written for APLX, but can also be used with Dyalog after some modifications.

The example shows how to contact an SMTP mail server which requires authentication - i.e. requires you to provide a user name and password when the SMTP connection is established. This is an increasingly common requirement designed to combat anonymous Spam e-mails.

Depending on the SMTP server you are using, you may need to make some small changes to the code:

 * The example uses port 25 to contact the SMTP server. Some authenticating servers use another port number.
 * The example uses SSL to establish a secure connection to the server. Not all SMTP servers support SSL.
 * The example uses supplies a user name and password to the server. Not all SMTP servers require authentication
 
{{{
SendMessage;to;from;message;smtpClient;credentials
⍝ Example of sending an E-Mail message using .NET
⍝ See
⍝ http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
 
⍝ Create a test message
to←'fredsmith@supernet.com'
from←'bob3@yahoo.com'
message←'.net' ⎕NEW 'System.Net.Mail.MailMessage' from to
message.Subject←'Pricing and Availability'
message.Body←'Did you get the new price list?',⎕R,'Thanks. Bob'
 
⍝ Create an SMTP client
⍝ (You may need to change the port number)
smtpClient←'.net' ⎕NEW 'System.Net.Mail.SmtpClient'
smtpClient.Host←'smtp.supernet.com'
smtpClient.Port←25
 
⍝ Set login credentials used to authenticate us to the SMTP server
⍝ (If your SMTP server doesn't use authentication, omit this bit)
credentials←'.net' ⎕new 'System.Net.NetworkCredential'
credentials.UserName←'myusername'
credentials.Password←'mysecretpassword'

smtpClient.Credentials←credentials
smtpClient.UseDefaultCredentials←0
 
⍝ Use SSL for secure connection
⍝ (If your SMTP server doesn't use SSL, omit this bit)
smtpClient.EnableSsl←1
 
⍝ Send the message
smtpClient.Send message
}}}


Author: SimonMarsden

----
CategoryAplx CategoryDotNet CategoryEmail

Sending E-mail using .NET

The following code shows how to send an e-mail using the .NET System.Mail namespace. The code is written for APLX, but can also be used with Dyalog after some modifications.

The example shows how to contact an SMTP mail server which requires authentication - i.e. requires you to provide a user name and password when the SMTP connection is established. This is an increasingly common requirement designed to combat anonymous Spam e-mails.

Depending on the SMTP server you are using, you may need to make some small changes to the code:

  • The example uses port 25 to contact the SMTP server. Some authenticating servers use another port number.
  • The example uses SSL to establish a secure connection to the server. Not all SMTP servers support SSL.
  • The example uses supplies a user name and password to the server. Not all SMTP servers require authentication

 

SendMessage;to;from;message;smtpClient;credentials
⍝ Example of sending an E-Mail message using .NET
⍝ See
⍝     http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
 
⍝ Create a test message
to←'fredsmith@supernet.com'
from←'bob3@yahoo.com'
message←'.net' ⎕NEW 'System.Net.Mail.MailMessage' from to
message.Subject←'Pricing and Availability'
message.Body←'Did you get the new price list?',⎕R,'Thanks. Bob'
 
⍝ Create an SMTP client
⍝ (You may need to change the port number)
smtpClient←'.net' ⎕NEW 'System.Net.Mail.SmtpClient'
smtpClient.Host←'smtp.supernet.com'
smtpClient.Port←25
 
⍝ Set login credentials used to authenticate us to the SMTP server
⍝ (If your SMTP server doesn't use authentication, omit this bit)
credentials←'.net' ⎕new 'System.Net.NetworkCredential'
credentials.UserName←'myusername'
credentials.Password←'mysecretpassword'

smtpClient.Credentials←credentials
smtpClient.UseDefaultCredentials←0
 
⍝ Use SSL for secure connection
⍝ (If your SMTP server doesn't use SSL, omit this bit)
smtpClient.EnableSsl←1
 
⍝ Send the message
smtpClient.Send message

Author: SimonMarsden


CategoryAplx CategoryDotNet CategoryEmail

AuthenticatedEmail (last edited 2017-02-16 19:40:56 by KaiJaeger)