WeixiangYan/CodeTransOcean huggingface dataset:
Task: String length





Java: String s = "Hello, world!"; 
int byteCountUTF16 = s.getBytes("UTF-16").length; 
int byteCountUTF16LE = s.getBytes("UTF-16LE").length; 
int byteCountUTF8  = s.getBytes("UTF-8").length; 


PHP: <?php
foreach (array('møøse', '𝔘𝔫𝔦𝔠𝔬𝔡𝔢', 'J̲o̲s̲é̲') as $s1) { 
   printf('String "%s" measured with strlen: %d mb_strlen: %s grapheme_strlen %s%s', 
                  $s1, strlen($s1),mb_strlen($s1), grapheme_strlen($s1), PHP_EOL);
}
Task: String length






PHP: <?php
foreach (array('møøse', '𝔘𝔫𝔦𝔠𝔬𝔡𝔢', 'J̲o̲s̲é̲') as $s1) { 
   printf('String "%s" measured with strlen: %d mb_strlen: %s grapheme_strlen %s%s', 
                  $s1, strlen($s1),mb_strlen($s1), grapheme_strlen($s1), PHP_EOL);
}


Python: print len('ascii')
Task: String length






PHP: <?php
foreach (array('møøse', '𝔘𝔫𝔦𝔠𝔬𝔡𝔢', 'J̲o̲s̲é̲') as $s1) { 
   printf('String "%s" measured with strlen: %d mb_strlen: %s grapheme_strlen %s%s', 
                  $s1, strlen($s1),mb_strlen($s1), grapheme_strlen($s1), PHP_EOL);
}



VB: Module ByteLength
    Function GetByteLength(s As String, encoding As Text.Encoding) As Integer
        Return encoding.GetByteCount(s)
    End Function
End Module
Task: Product of min and max prime factors

C: #include <stdbool.h>
#include <stdio.h>
#include <string.h>

#define MAX 100

void sieve(bool *prime, int max) {
    memset(prime, true, max+1);
    prime[0] = prime[1] = false;
    
    for (int p=2; p*p<=max; p++)
        for (int c=p*p; c<=max; c+=p)
            prime[c] = false; 
}

int lo_fac(bool *prime, int n) {
    if (n==1) return 1;
    for (int f=2; f<=n; f++) 
        if (prime[f] && n%f == 0) return f;
    return n;
}

int hi_fac(bool *prime, int n) {
    if (n==1) return 1;
    for (int f=n; f>=2; f--)
        if (prime[f] && n%f == 0) return f;
    return n;
}

int main() {
    bool prime[MAX+1];
    sieve(prime, MAX);
    
    for (int i=1; i<=MAX; i++) {
        printf("%6d", lo_fac(prime, i) * hi_fac(prime, i));
        if (i%10 == 0) printf("\n");
    }
    return 0;
}



C#: #include <iomanip>
#include <iostream>
#include <utility>

auto min_max_prime_factors(unsigned int n) {
    unsigned int min_factor = 1;
    unsigned int max_factor = 1;
    if ((n & 1) == 0) {
        while ((n & 1) == 0)
            n >>= 1;
        min_factor = 2;
        max_factor = 2;
    }
    for (unsigned int p = 3; p * p <= n; p += 2) {
        if (n % p == 0) {
            while (n % p == 0)
                n /= p;
            if (min_factor == 1)
                min_factor = p;
            max_factor = p;
        }
    }
    if (n > 1) {
        if (min_factor == 1)
            min_factor = n;
        max_factor = n;
    }
    return std::make_pair(min_factor, max_factor);
}

int main() {
    std::cout << "Product of smallest and greatest prime factors of n for 1 to "
                 "100:\n";
    for (unsigned int n = 1; n <= 100; ++n) {
        auto p = min_max_prime_factors(n);
        std::cout << std::setw(4) << p.first * p.second
                  << (n % 10 == 0 ? '\n' : ' ');
    }
}
Task: Product of min and max prime factors

C: #include <stdbool.h>
#include <stdio.h>
#include <string.h>

#define MAX 100

void sieve(bool *prime, int max) {
    memset(prime, true, max+1);
    prime[0] = prime[1] = false;
    
    for (int p=2; p*p<=max; p++)
        for (int c=p*p; c<=max; c+=p)
            prime[c] = false; 
}

int lo_fac(bool *prime, int n) {
    if (n==1) return 1;
    for (int f=2; f<=n; f++) 
        if (prime[f] && n%f == 0) return f;
    return n;
}

int hi_fac(bool *prime, int n) {
    if (n==1) return 1;
    for (int f=n; f>=2; f--)
        if (prime[f] && n%f == 0) return f;
    return n;
}

int main() {
    bool prime[MAX+1];
    sieve(prime, MAX);
    
    for (int i=1; i<=MAX; i++) {
        printf("%6d", lo_fac(prime, i) * hi_fac(prime, i));
        if (i%10 == 0) printf("\n");
    }
    return 0;
}







Python: 


from sympy import factorint

NUM_WANTED = 100

for num in range(1, NUM_WANTED + 1):
    fac = factorint(num, multiple=True)
    product = fac[0] * fac[-1] if len(fac) > 0 else 1
    print(f'{product:5}', end='\n' if num % 10 == 0 else '')
Task: Product of min and max prime factors


C++: #include <iomanip>
#include <iostream>
#include <utility>

auto min_max_prime_factors(unsigned int n) {
    unsigned int min_factor = 1;
    unsigned int max_factor = 1;
    if ((n & 1) == 0) {
        while ((n & 1) == 0)
            n >>= 1;
        min_factor = 2;
        max_factor = 2;
    }
    for (unsigned int p = 3; p * p <= n; p += 2) {
        if (n % p == 0) {
            while (n % p == 0)
                n /= p;
            if (min_factor == 1)
                min_factor = p;
            max_factor = p;
        }
    }
    if (n > 1) {
        if (min_factor == 1)
            min_factor = n;
        max_factor = n;
    }
    return std::make_pair(min_factor, max_factor);
}

int main() {
    std::cout << "Product of smallest and greatest prime factors of n for 1 to "
                 "100:\n";
    for (unsigned int n = 1; n <= 100; ++n) {
        auto p = min_max_prime_factors(n);
        std::cout << std::setw(4) << p.first * p.second
                  << (n % 10 == 0 ? '\n' : ' ');
    }
}






Python: 


from sympy import factorint

NUM_WANTED = 100

for num in range(1, NUM_WANTED + 1):
    fac = factorint(num, multiple=True)
    product = fac[0] * fac[-1] if len(fac) > 0 else 1
    print(f'{product:5}', end='\n' if num % 10 == 0 else '')
Task: Product of min and max prime factors




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    prods := make([]int, 100)
    prods[0] = 1
    for i := 2; i <= 100; i++ {
        factors := rcu.PrimeFactors(i)
        prods[i-1] = factors[0] * factors[len(factors)-1]
    }
    fmt.Println("Product of smallest and greatest prime factors of n for 1 to 100:")
    rcu.PrintTable(prods, 10, 4, false)
}




Python: 


from sympy import factorint

NUM_WANTED = 100

for num in range(1, NUM_WANTED + 1):
    fac = factorint(num, multiple=True)
    product = fac[0] * fac[-1] if len(fac) > 0 else 1
    print(f'{product:5}', end='\n' if num % 10 == 0 else '')
Task: Product of min and max prime factors

C: #include <stdbool.h>
#include <stdio.h>
#include <string.h>

#define MAX 100

void sieve(bool *prime, int max) {
    memset(prime, true, max+1);
    prime[0] = prime[1] = false;
    
    for (int p=2; p*p<=max; p++)
        for (int c=p*p; c<=max; c+=p)
            prime[c] = false; 
}

int lo_fac(bool *prime, int n) {
    if (n==1) return 1;
    for (int f=2; f<=n; f++) 
        if (prime[f] && n%f == 0) return f;
    return n;
}

int hi_fac(bool *prime, int n) {
    if (n==1) return 1;
    for (int f=n; f>=2; f--)
        if (prime[f] && n%f == 0) return f;
    return n;
}

int main() {
    bool prime[MAX+1];
    sieve(prime, MAX);
    
    for (int i=1; i<=MAX; i++) {
        printf("%6d", lo_fac(prime, i) * hi_fac(prime, i));
        if (i%10 == 0) printf("\n");
    }
    return 0;
}


C++: #include <iomanip>
#include <iostream>
#include <utility>

auto min_max_prime_factors(unsigned int n) {
    unsigned int min_factor = 1;
    unsigned int max_factor = 1;
    if ((n & 1) == 0) {
        while ((n & 1) == 0)
            n >>= 1;
        min_factor = 2;
        max_factor = 2;
    }
    for (unsigned int p = 3; p * p <= n; p += 2) {
        if (n % p == 0) {
            while (n % p == 0)
                n /= p;
            if (min_factor == 1)
                min_factor = p;
            max_factor = p;
        }
    }
    if (n > 1) {
        if (min_factor == 1)
            min_factor = n;
        max_factor = n;
    }
    return std::make_pair(min_factor, max_factor);
}

int main() {
    std::cout << "Product of smallest and greatest prime factors of n for 1 to "
                 "100:\n";
    for (unsigned int n = 1; n <= 100; ++n) {
        auto p = min_max_prime_factors(n);
        std::cout << std::setw(4) << p.first * p.second
                  << (n % 10 == 0 ? '\n' : ' ');
    }
}
Task: Product of min and max prime factors


C++: #include <iomanip>
#include <iostream>
#include <utility>

auto min_max_prime_factors(unsigned int n) {
    unsigned int min_factor = 1;
    unsigned int max_factor = 1;
    if ((n & 1) == 0) {
        while ((n & 1) == 0)
            n >>= 1;
        min_factor = 2;
        max_factor = 2;
    }
    for (unsigned int p = 3; p * p <= n; p += 2) {
        if (n % p == 0) {
            while (n % p == 0)
                n /= p;
            if (min_factor == 1)
                min_factor = p;
            max_factor = p;
        }
    }
    if (n > 1) {
        if (min_factor == 1)
            min_factor = n;
        max_factor = n;
    }
    return std::make_pair(min_factor, max_factor);
}

int main() {
    std::cout << "Product of smallest and greatest prime factors of n for 1 to "
                 "100:\n";
    for (unsigned int n = 1; n <= 100; ++n) {
        auto p = min_max_prime_factors(n);
        std::cout << std::setw(4) << p.first * p.second
                  << (n % 10 == 0 ? '\n' : ' ');
    }
}



Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    prods := make([]int, 100)
    prods[0] = 1
    for i := 2; i <= 100; i++ {
        factors := rcu.PrimeFactors(i)
        prods[i-1] = factors[0] * factors[len(factors)-1]
    }
    fmt.Println("Product of smallest and greatest prime factors of n for 1 to 100:")
    rcu.PrintTable(prods, 10, 4, false)
}
Task: Product of min and max prime factors

C: #include <stdbool.h>
#include <stdio.h>
#include <string.h>

#define MAX 100

void sieve(bool *prime, int max) {
    memset(prime, true, max+1);
    prime[0] = prime[1] = false;
    
    for (int p=2; p*p<=max; p++)
        for (int c=p*p; c<=max; c+=p)
            prime[c] = false; 
}

int lo_fac(bool *prime, int n) {
    if (n==1) return 1;
    for (int f=2; f<=n; f++) 
        if (prime[f] && n%f == 0) return f;
    return n;
}

int hi_fac(bool *prime, int n) {
    if (n==1) return 1;
    for (int f=n; f>=2; f--)
        if (prime[f] && n%f == 0) return f;
    return n;
}

int main() {
    bool prime[MAX+1];
    sieve(prime, MAX);
    
    for (int i=1; i<=MAX; i++) {
        printf("%6d", lo_fac(prime, i) * hi_fac(prime, i));
        if (i%10 == 0) printf("\n");
    }
    return 0;
}




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    prods := make([]int, 100)
    prods[0] = 1
    for i := 2; i <= 100; i++ {
        factors := rcu.PrimeFactors(i)
        prods[i-1] = factors[0] * factors[len(factors)-1]
    }
    fmt.Println("Product of smallest and greatest prime factors of n for 1 to 100:")
    rcu.PrintTable(prods, 10, 4, false)
}
Task: Send email

C: #include <curl/curl.h>
#include <string.h>
#include <stdio.h>

#define from    "<sender@duniya.com>"
#define to      "<addressee@gmail.com>"
#define cc      "<info@example.org>"
 
static const char *payload_text[] = {
  "Date: Mon, 13 Jun 2018 11:30:00 +0100\r\n",
  "To: " to "\r\n",
  "From: " from " (Example User)\r\n",
  "Cc: " cc " (Another example User)\r\n",
  "Message-ID: <ecd7db36-10ab-437a-9g3a-e652b9458efd@"
  "rfcpedant.example.org>\r\n",
  "Subject: Sanding mail via C\r\n",
  "\r\n",
  "This mail is being sent by a C program.\r\n",
  "\r\n",
  "It connects to the GMail SMTP server, by far, the most popular mail program of all.\r\n",
  "Which is also probably written in C.\r\n",
  "To C or not to C..............\r\n",
  "That is the question.\r\n",
  NULL
};
 
struct upload_status {
  int lines_read;
};
 
static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp)
{
  struct upload_status *upload_ctx = (struct upload_status *)userp;
  const char *data;
 
  if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
    return 0;
  }
 
  data = payload_text[upload_ctx->lines_read];
 
  if(data) {
    size_t len = strlen(data);
    memcpy(ptr, data, len);
    upload_ctx->lines_read++;
 
    return len;
  }
 
  return 0;
}
 
int main(void)
{
  CURL *curl;
  CURLcode res = CURLE_OK;
  struct curl_slist *recipients = NULL;
  struct upload_status upload_ctx;
 
  upload_ctx.lines_read = 0;
 
  curl = curl_easy_init();
  if(curl) {

    curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
    curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");

    curl_easy_setopt(curl, CURLOPT_URL, "smtp:

    curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
 
    curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem");

    curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);

    recipients = curl_slist_append(recipients, to);
    recipients = curl_slist_append(recipients, cc);
    curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);

    curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
    curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);

    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    res = curl_easy_perform(curl);

    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));

    curl_slist_free_all(recipients);

    curl_easy_cleanup(curl);
  }
 
  return (int)res;
}



C#: static void Main(string[] args)
{
    

    SmtpClient SMTP = new SmtpClient("smtp.gmail.com", 587); 
    SMTP.EnableSsl = true; 
    SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
    SMTP.Credentials = new NetworkCredential("YourUserName", "YourPassword");
    MailMessage Mail = new MailMessage("yourEmail@address.com", "theirEmail@address.com");


    

    Mail.Subject = "Important Message";
    Mail.Body = "Hello over there"; 
    

    

    SMTP.Send(Mail);

    Console.WriteLine("Message Sent");
}
Task: Send email

C: #include <curl/curl.h>
#include <string.h>
#include <stdio.h>

#define from    "<sender@duniya.com>"
#define to      "<addressee@gmail.com>"
#define cc      "<info@example.org>"
 
static const char *payload_text[] = {
  "Date: Mon, 13 Jun 2018 11:30:00 +0100\r\n",
  "To: " to "\r\n",
  "From: " from " (Example User)\r\n",
  "Cc: " cc " (Another example User)\r\n",
  "Message-ID: <ecd7db36-10ab-437a-9g3a-e652b9458efd@"
  "rfcpedant.example.org>\r\n",
  "Subject: Sanding mail via C\r\n",
  "\r\n",
  "This mail is being sent by a C program.\r\n",
  "\r\n",
  "It connects to the GMail SMTP server, by far, the most popular mail program of all.\r\n",
  "Which is also probably written in C.\r\n",
  "To C or not to C..............\r\n",
  "That is the question.\r\n",
  NULL
};
 
struct upload_status {
  int lines_read;
};
 
static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp)
{
  struct upload_status *upload_ctx = (struct upload_status *)userp;
  const char *data;
 
  if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
    return 0;
  }
 
  data = payload_text[upload_ctx->lines_read];
 
  if(data) {
    size_t len = strlen(data);
    memcpy(ptr, data, len);
    upload_ctx->lines_read++;
 
    return len;
  }
 
  return 0;
}
 
int main(void)
{
  CURL *curl;
  CURLcode res = CURLE_OK;
  struct curl_slist *recipients = NULL;
  struct upload_status upload_ctx;
 
  upload_ctx.lines_read = 0;
 
  curl = curl_easy_init();
  if(curl) {

    curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
    curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");

    curl_easy_setopt(curl, CURLOPT_URL, "smtp:

    curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
 
    curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem");

    curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);

    recipients = curl_slist_append(recipients, to);
    recipients = curl_slist_append(recipients, cc);
    curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);

    curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
    curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);

    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    res = curl_easy_perform(curl);

    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));

    curl_slist_free_all(recipients);

    curl_easy_cleanup(curl);
  }
 
  return (int)res;
}








VB: Option Explicit
Const olMailItem = 0

Sub SendMail(MsgTo As String, MsgTitle As String, MsgBody As String)
    Dim OutlookApp As Object, Msg As Object
    Set OutlookApp = CreateObject("Outlook.Application")
    Set Msg = OutlookApp.CreateItem(olMailItem)
    With Msg
        .To = MsgTo
        .Subject = MsgTitle
        .Body = MsgBody
        .Send
    End With
    Set OutlookApp = Nothing
End Sub

Sub Test()
    SendMail "somebody@somewhere", "Title", "Hello"
End Sub
Task: Send email


C++: 



#include <cstdlib>
#include <iostream>
#include <Poco/Net/SMTPClientSession.h>
#include <Poco/Net/MailMessage.h>

using namespace Poco::Net;

int main (int argc, char **argv)
{
  try
    {
      MailMessage msg;

      msg.addRecipient (MailRecipient (MailRecipient::PRIMARY_RECIPIENT,
                                       "alice@example.com",
                                       "Alice Moralis"));
      msg.addRecipient (MailRecipient (MailRecipient::CC_RECIPIENT,
                                       "pat@example.com",
                                       "Patrick Kilpatrick"));
      msg.addRecipient (MailRecipient (MailRecipient::BCC_RECIPIENT,
                                       "mike@example.com",
                                       "Michael Carmichael"));

      msg.setSender ("Roy Kilroy <roy@example.com>");

      msg.setSubject ("Rosetta Code");
      msg.setContent ("Sending mail from C++ using POCO C++ Libraries");

      SMTPClientSession smtp ("mail.example.com"); 
      smtp.login ();
      smtp.sendMessage (msg);
      smtp.close ();
      std::cerr << "Sent mail successfully!" << std::endl;
    }
  catch (std::exception &e)
    {
      std::cerr << "failed to send mail: " << e.what() << std::endl;
      return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}




Java: import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class Mail
{
 
 protected Session session;

 
 public Mail(String host)
 {
  Properties properties = new Properties();
  properties.put("mail.smtp.host", host);
  session = Session.getDefaultInstance(properties);
 }

 
 public void send(String from, String tos[], String ccs[], String subject,
        String text)
        throws MessagingException
 {
  MimeMessage message = new MimeMessage(session);
  message.setFrom(new InternetAddress(from));
  for (String to : tos)
   message.addRecipient(RecipientType.TO, new InternetAddress(to));
  for (String cc : ccs)
   message.addRecipient(RecipientType.TO, new InternetAddress(cc));
  message.setSubject(subject);
  message.setText(text);
  Transport.send(message);
 }
}
Task: Send email


C++: 



#include <cstdlib>
#include <iostream>
#include <Poco/Net/SMTPClientSession.h>
#include <Poco/Net/MailMessage.h>

using namespace Poco::Net;

int main (int argc, char **argv)
{
  try
    {
      MailMessage msg;

      msg.addRecipient (MailRecipient (MailRecipient::PRIMARY_RECIPIENT,
                                       "alice@example.com",
                                       "Alice Moralis"));
      msg.addRecipient (MailRecipient (MailRecipient::CC_RECIPIENT,
                                       "pat@example.com",
                                       "Patrick Kilpatrick"));
      msg.addRecipient (MailRecipient (MailRecipient::BCC_RECIPIENT,
                                       "mike@example.com",
                                       "Michael Carmichael"));

      msg.setSender ("Roy Kilroy <roy@example.com>");

      msg.setSubject ("Rosetta Code");
      msg.setContent ("Sending mail from C++ using POCO C++ Libraries");

      SMTPClientSession smtp ("mail.example.com"); 
      smtp.login ();
      smtp.sendMessage (msg);
      smtp.close ();
      std::cerr << "Sent mail successfully!" << std::endl;
    }
  catch (std::exception &e)
    {
      std::cerr << "failed to send mail: " << e.what() << std::endl;
      return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}






Python: import smtplib

def sendemail(from_addr, to_addr_list, cc_addr_list,
              subject, message,
              login, password,
              smtpserver='smtp.gmail.com:587'):
    header  = 'From: %s\n' % from_addr
    header += 'To: %s\n' % ','.join(to_addr_list)
    header += 'Cc: %s\n' % ','.join(cc_addr_list)
    header += 'Subject: %s\n\n' % subject
    message = header + message
    
    server = smtplib.SMTP(smtpserver)
    server.starttls()
    server.login(login,password)
    problems = server.sendmail(from_addr, to_addr_list, message)
    server.quit()
    return problems
Task: Send email


C++: 



#include <cstdlib>
#include <iostream>
#include <Poco/Net/SMTPClientSession.h>
#include <Poco/Net/MailMessage.h>

using namespace Poco::Net;

int main (int argc, char **argv)
{
  try
    {
      MailMessage msg;

      msg.addRecipient (MailRecipient (MailRecipient::PRIMARY_RECIPIENT,
                                       "alice@example.com",
                                       "Alice Moralis"));
      msg.addRecipient (MailRecipient (MailRecipient::CC_RECIPIENT,
                                       "pat@example.com",
                                       "Patrick Kilpatrick"));
      msg.addRecipient (MailRecipient (MailRecipient::BCC_RECIPIENT,
                                       "mike@example.com",
                                       "Michael Carmichael"));

      msg.setSender ("Roy Kilroy <roy@example.com>");

      msg.setSubject ("Rosetta Code");
      msg.setContent ("Sending mail from C++ using POCO C++ Libraries");

      SMTPClientSession smtp ("mail.example.com"); 
      smtp.login ();
      smtp.sendMessage (msg);
      smtp.close ();
      std::cerr << "Sent mail successfully!" << std::endl;
    }
  catch (std::exception &e)
    {
      std::cerr << "failed to send mail: " << e.what() << std::endl;
      return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}







VB: Option Explicit
Const olMailItem = 0

Sub SendMail(MsgTo As String, MsgTitle As String, MsgBody As String)
    Dim OutlookApp As Object, Msg As Object
    Set OutlookApp = CreateObject("Outlook.Application")
    Set Msg = OutlookApp.CreateItem(olMailItem)
    With Msg
        .To = MsgTo
        .Subject = MsgTitle
        .Body = MsgBody
        .Send
    End With
    Set OutlookApp = Nothing
End Sub

Sub Test()
    SendMail "somebody@somewhere", "Title", "Hello"
End Sub
Task: Send email



C#: static void Main(string[] args)
{
    

    SmtpClient SMTP = new SmtpClient("smtp.gmail.com", 587); 
    SMTP.EnableSsl = true; 
    SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
    SMTP.Credentials = new NetworkCredential("YourUserName", "YourPassword");
    MailMessage Mail = new MailMessage("yourEmail@address.com", "theirEmail@address.com");


    

    Mail.Subject = "Important Message";
    Mail.Body = "Hello over there"; 
    

    

    SMTP.Send(Mail);

    Console.WriteLine("Message Sent");
}



Java: import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class Mail
{
 
 protected Session session;

 
 public Mail(String host)
 {
  Properties properties = new Properties();
  properties.put("mail.smtp.host", host);
  session = Session.getDefaultInstance(properties);
 }

 
 public void send(String from, String tos[], String ccs[], String subject,
        String text)
        throws MessagingException
 {
  MimeMessage message = new MimeMessage(session);
  message.setFrom(new InternetAddress(from));
  for (String to : tos)
   message.addRecipient(RecipientType.TO, new InternetAddress(to));
  for (String cc : ccs)
   message.addRecipient(RecipientType.TO, new InternetAddress(cc));
  message.setSubject(subject);
  message.setText(text);
  Transport.send(message);
 }
}