I use "Get message" to read mail form Exchange, but i can't finde the authentication provider
Dim sClientID As String = "xxx"
Dim sClientSecret As String = "xxx"
Dim sAppScopes As String() = New String() {"https://graph.microsoft.com/.default"}
Dim STenanID As String = "xxx"
Dim options = New TokenCredentialOptions With {.AuthorityHost = AzureAuthorityHosts.AzurePublicCloud}
Dim clientSecretCredential = New ClientSecretCredential(STenanID, sClientID, sClientSecret, options)
client = New GraphServiceClient(clientSecretCredential, sAppScopes)
Related
I was try to connect my TFS server using my credentials . But i am getting error 'Basic authentication requires a secure connection to the server.'
string username = "adminuser";
string pwd = "mypassword";
string domain = "http://localhost:8080/tfs/defaultcollection";
NetworkCredential networkCredential = new NetworkCredential(username, pwd);
BasicAuthCredential basicAuthCredential = new BasicAuthCredential(networkCredential);
TfsClientCredentials tfsClientCredentials = new TfsClientCredentials(basicAuthCredential)
{
AllowInteractive = false
};
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(domain), tfsClientCredentials);
tfs.EnsureAuthenticated();
My tfs didn't have the https. Any alternative to fix it But browser level it is working fine
The BasicAuthCredential requires https://, I believe, and I wasn't able to access my TFS with https://. So I found another way to get from NetworkCredential to VssCredentials.
string username = "adminuser";
string pwd = "mypassword";
string domain = "http://localhost:8080/tfs/defaultcollection";
NetworkCredential networkCredential = new NetworkCredential(username, pwd);
//BasicAuthCredential basicAuthCredential = new BasicAuthCredential(networkCredential);
Microsoft.VisualStudio.Services.Common.WindowsCredential winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(networkCredential);
VssCredentials vssCred = new VssClientCredentials(winCred);
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(domain), vssCred);
tfs.EnsureAuthenticated();
Try using the following code:
String collectionUri = "http://localhost:8080/tfs/defaultcollection";
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
VssConnection connection = new VssConnection(new Uri(collectionUri), creds);
i'm actually trying to create registration page with verfication mail using MVC in visual studio, but here to send a message im getting
error : 'RandLform.Controllers.MailMessage' to 'System.Net.Mail.MailMessage' RandLform
public void SendVerficationLinkEmail(string emailID, string activationCode)
{
var VerifyUrl = "/User/VerifyAccount/" + activationCode;
var link = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, VerifyUrl);
var fromEmail = new MailAddress("lokeshkingdom4u#gmail.com", "Lokesh Pladugula");
var toEmail = new MailAddress(emailID);
var fromEmailPassword = "paisa007";
string subject = "Account created Succesfully!";
string body = "<br/>To verify your account, click on below link.<br/><br/> "+" "+link+"";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NewNetworkCredential(fromEmail.Address, fromEmailPassword)
};
using (var message = new MailMessage(fromEmail, toEmail)
{
Subject = subject,
Body = body,
IsBodyHtml = true
})
smtp.Send(message);
}
Lokesh Paladugula,
I recommend you to change password of your email account.
I'm not sure if this is actual error, please send proper error.
I how can I have email encrypted and signed ?
Seem that I can either encrypt or signed but not both.
Below is my code
public void SendEncryptedEmail04(
//string SigningCertPath, string EncryptingCertPath,
String sender, String To,
string Subject, string Body,
// string SmtpServer, int SmtpPort, bool HTML)
bool HTML)
{
X509Certificate2 SignCert = new X509Certificate2("D:\\certwithprivatekey.pfx", "password"));
X509Certificate2 EncryptCert = new X509Certificate2("abc#gmail.crt", "");
StringBuilder Message = new StringBuilder();
Message.AppendLine("Content-Type: text/" + ((HTML) ? "html" : "plain") +
"; charset=\"iso-8859-1\"");
Message.AppendLine("Content-Transfer-Encoding: 7bit");
Message.AppendLine();
Message.AppendLine(Body);
byte[] BodyBytes = Encoding.ASCII.GetBytes(Message.ToString());
EnvelopedCms ECms = new EnvelopedCms(new ContentInfo(BodyBytes));
CmsRecipient Recipient = new CmsRecipient(
SubjectIdentifierType.IssuerAndSerialNumber, EncryptCert);
ECms.Encrypt(Recipient);
byte[] EncryptedBytes = ECms.Encode();
SignedCms Cms = new SignedCms(new ContentInfo(EncryptedBytes));
CmsSigner Signer = new CmsSigner
(SubjectIdentifierType.IssuerAndSerialNumber, SignCert);
Cms.ComputeSignature(Signer);
byte[] SignedBytes = Cms.Encode();
MailMessage Msg = new MailMessage();
Msg.To.Add(new MailAddress(To));
Msg.From = new MailAddress(sender);
Msg.Subject = Subject;
//MemoryStream ms = new MemoryStream(EncryptedBytes);
MemoryStream ms = new MemoryStream(SignedBytes);
AlternateView av = new AlternateView(ms,
"application/pkcs7-mime; smime-type=signed-data;name=smime.p7m");
//"application/pkcs7-mime; smime-type=enveloped-data;name=smime.p7m");
Msg.AlternateViews.Add(av);
SmtpClient smtp = new SmtpClient(emailServer, 25);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(sender,"xxxx"));
smtp.Send(Msg);
}
The email received by ThunderBird has the following
However, I changed to
MemoryStream ms = new MemoryStream(EncryptedBytes);
I have
How can I have encrypted and signed ?
Thanks
I have a VBScript file to send the emails It works fine, but when I created a C# program (.Net 4.5) with the same CDO settings I got
The transport failed to connect to the server.
Please check what is the problem with my C#.
VBScript:
Dim objMessage
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = Subj
objMessage.From = Sender
objMessage.To = Receivers
objMessage.TextBody = Body
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ServerName
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = ""
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
objMessage.Configuration.Fields.Update
objMessage.Send
C#:
using System.Net.Mail;
...
CDO.Message objMessage = new CDO.Message();
objMessage.Subject = Subj;
objMessage.From = Sender;
objMessage.To = Receivers;
objMessage.TextBody = Body;
ADODB.Field FieldSMTPSendUsing = objMessage.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
FieldSMTPSendUsing.Value = 2;
ADODB.Field FieldSMTPServer = objMessage.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
FieldSMTPServer.Value = ServerName;
ADODB.Field FieldSMTPServerPort = objMessage.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
FieldSMTPServerPort.Value = 25;
ADODB.Field FieldSMTPconnectiontimeout = objMessage.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"];
FieldSMTPconnectiontimeout.Value = 60 ;
ADODB.Field FieldSMTPauthenticate = objMessage.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
FieldSMTPauthenticate.Value = 2;
ADODB.Field FieldSMTPsendusername = objMessage.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"];
FieldSMTPsendusername.Value = "";
ADODB.Field FieldSMTPsendpassword = objMessage.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
FieldSMTPsendpassword.Value = "";
ADODB.Field FieldSMTPusessl = objMessage.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
FieldSMTPusessl.Value = false;
objMessage.Configuration.Fields.Update();
objMessage.Send();
Don't use CDO in C#. Use the MailMessage class for composing messages, and the SmtpClient class for sending them.
MailMessage message = new MailMessage(Sender, Receivers, Subj, Body);
SmtpClient client = new SmtpClient(ServerName);
try {
client.Send(message);
} catch (Exception ex) {
Console.WriteLine("Cannot send message.");
}
The problem: I get "???????" instead of display name of sender (display name is the utf8 text, also tried using System.Web.Mail.MailMessage but got the same result):
var fromAddress = new MailAddress("from#mail.com", "Some UTF8 text");
var toAddress = new MailAddress(toAddress);
var client = new SmtpClient
{
Host = "smpt.server",
Port = 465,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, "password"),
Timeout = 5000
};
var message = new MailMessage(fromAddress, toAddress)
{
Subject = title,
Body = messageStr,
IsBodyHtml = true
};
Have you tried changing the constructor?
var fromAddress = new MailAddress("from#mail.com", "Some UTF8 text", System.Text.Encoding.UTF8);
MailAddress Constructor (String, String, Encoding)