मैंने Outlook Office365 का उपयोग करके ईमेल भेजने के लिए कोड के नीचे लिखा है।

ExchangeService myService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
myService.Credentials = new WebCredentials(sender_mailId,sender_password);

try
{
  string serviceUrl = <<service url>> // This URL 
  myService.Url = new Uri(serviceUrl);
  EmailMessage emailMessage = new EmailMessage(myservice);
  emailMessage.Subject = "Subject test ";
  emailMessage.Body = new MessageBody("Testing Exchange Web Service API");
  emailMessage.ToRecipients.Add(to_email_id);
  emailMessage.Send();
}
catch (SmtpException exception)
{
  string msg = "Mail cannot be sent (SmtpException):";
  msg += exception.Message;
  throw new Exception(msg);
}

किस वेब सेवा URL का उपयोग किया जाना चाहिए?

c#
0
Amaresh Hiremath 19 मार्च 2020, 17:28

1 उत्तर

सबसे बढ़िया उत्तर

ईमेल ड्राफ्ट को भेजने या सहेजने के लिए नीचे दिया गया कोड काम करता है।

static void CheckEmail()
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Credentials = new WebCredentials(senderEmailId, password);
 service.AutodiscoverUrl(senderEmailId, RedirectionUrlValidationCallback);

 EmailMessage emailMessage = new EmailMessage(service);
 emailMessage.Subject = "Test office 365 project draft ";
 emailMessage.Body = new MessageBody("Testing Exchange Web Service API");

 emailMessage.ToRecipients.Add(emailTo);

//send email
emailMessage.Send();

//save to draft
emailMessage.Save(WellKnownFolderName.Drafts);
}

   private static bool RedirectionUrlValidationCallback(string redirectionUrl)
    {
        // The default for the validation callback is to reject the URL.
        bool result = false;

        Uri redirectionUri = new Uri(redirectionUrl);

        // Validate the contents of the redirection URL. In this simple validation
        // callback, the redirection URL is considered valid if it is using HTTPS
        // to encrypt the authentication credentials. 
        if (redirectionUri.Scheme == "https")
        {
            result = true;
        }
        return result;
    }
0
Amaresh Hiremath 2 अप्रैल 2020, 11:48