I have been ask this question for few days but no answer, i am very new to Umbraco and junior of programming.i am working on trying to get admin user to reset password when they are forget their password and sent them an email to reset their password, after they
reset they password they will get a new password to login when they
login they we will force them to change password, so for now i am
struggle on the HandleForgottenPassword, getting
Object reference not set to an instance of an object. on the yellow line,
enter code here
[HttpPost]
[Authorize]
[ValidateAntiForgeryToken]
public ActionResult HandleForgottenPassword(ForgottenPasswordViewModel model)
{
if (!ModelState.IsValid)
{
return PartialView("ForgottenPassword", model);
}
//Find the member with the email address
var name =Member.GetMemberFromLoginName(model.LoginName);
var findMember = Member.GetMemberFromEmail(model.EmailAddress);
if (findMember != null)
{
//We found the member with that email
//Set expiry date to
DateTime expiryTime = DateTime.Now.AddMinutes(15);
//Lets update resetGUID property
// findMember.getProperty("resetGUID").Value = expiryTime.ToString("ddMMyyyyHHmmssFFFF");
//Save the member with the up[dated property value
findMember.Save();
//Send user an email to reset password with GUID in it
EmailHelper email = new EmailHelper();
email.SendResetPasswordEmail(findMember.Email, expiryTime.ToString("ddMMyyyyHHmmssFFFF"));
}
else
{
ModelState.AddModelError("ForgottenPasswordForm.", "No member found");
return PartialView("ForgottenPassword", model);
}
return PartialView("ForgottenPassword", model);
}
please help with sending email ( using EmailHelper from the package)
private const string SendGridUsername = "sendGridUsername";
private const string SendGridPassword = "sendGridPassword";
private const string EmailFromAddress = "you#yoursite.com";
public void SendResetPasswordEmail(string memberEmail, string resetGUID)
{
//Send a reset email to member
// Create the email object first, then add the properties.
var myMessage = SendGrid.GetInstance();
// Add the message properties.
myMessage.From = new MailAddress(EmailFromAddress);
//Send to the member's email address
myMessage.AddTo(memberEmail);
//Subject
myMessage.Subject = "Umb Jobs - Reset Your Password";
//Reset link
string baseURL = HttpContext.Current.Request.Url.AbsoluteUri.Replace(HttpContext.Current.Request.Url.AbsolutePath, string.Empty);
var resetURL = baseURL + "/reset-password?resetGUID=" + resetGUID;
//HTML Message
myMessage.Html = string.Format(
"<h3>Reset Your Password</h3>" +
"<p>You have requested to reset your password<br/>" +
"If you have not requested to reste your password, simply ignore this email and delete it</p>" +
"<p><a href='{0}'>Reset your password</a></p>", resetURL);
//PlainText Message
myMessage.Text = string.Format(
"Reset your password" + Environment.NewLine +
"You have requested to reset your password" + Environment.NewLine +
"If you have not requested to reste your password, simply ignore this email and delete it" +
Environment.NewLine + Environment.NewLine +
"Reset your password: {0}",
resetURL);
// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential(SendGridUsername, SendGridPassword);
// Create an SMTP transport for sending email.
var transportSMTP = SMTP.GetInstance(credentials);
// Send the email.
transportSMTP.Deliver(myMessage);
}
when i try to sending the email i got this erro
Unable to read data from the transport connection: net_io_connectionclosed.
here is my *web.config *
<system.net>
<mailSettings>
<smtp>
<network host="127.0.0.1" userName="username" password="password" />
</smtp>
</mailSettings>
</system.net>
Thank you in advance. MC
If you are on a residential internet connection quite often your ISP will block outgoing email sends by blocking all outbound connections to port 25. This is quite common in the US. Try connecting to a local email server over TCP/IP, or to one on your own internal network.
Related
I am unable to get the incoming message, and my response is not being sent back to the person
I have the following set up in SmsController
using System;
using System.Net.Mail;
using System.Configuration;
using System.Web.Mvc;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using Twilio.AspNet.Common;
using Twilio.TwiML;
using Twilio.AspNet.Mvc;
using Chat.Models;
public class SmsController : TwilioController
{
[HttpPost]
public TwiMLResult ReceiveSms(SmsRequest incomingMessage)
{
try
{
Applicant applicant = new Applicant();
string Phone = incomingMessage.From;
string UserID = applicant.GetUserIDByTelephone(Phone);
string MgrName = applicant.GetMessageSender(UserID);
string ApplicantName = applicant.GetName(UserID);
//Get the Message and the MessageID
string Body = incomingMessage.Body;
string MessageSid = incomingMessage.SmsSid;
//Save incoming message in the database
applicant.IncomingMessage(UserID, Body, MessageSid);
//Send applicant a message acknowledging that the text was received.
var response = new MessagingResponse();
response.Message("Thank you for your response. We will respond to your message shortly.");
//Get information on the manager
Manager manager = new Manager();
string MgrID = manager.GetMgrID(MgrName);
string email = manager.GetMgrEmail(MgrID);
bool notify = manager.Notify(MgrID);
//Send the email notification if manager set to receive notification.
if (notify)
{
SendEmail(email, ApplicantName, Body);
}
return TwiML(response);
}
catch (Exception ex)
{
Errors.ErrorOccured(ex,"message sent = " + incomingMessage.Body);
MessagingResponse messagingResponse = new MessagingResponse();
messagingResponse.Message("oops.. An error has occured.");
return TwiML(messagingResponse);
}
}
}
I have the Webhook set in Twilio
https://www.myUrl/admin/applicantmanagement/Sms/ReceiveSms
The above is the address for this particular MVC APP.
Yet I am not receiving the response from the user
So that was when I added the try catch as this line is set to send me an email on any errors that occur in the model or controller
Errors.ErrorOccured(ex,"message sent = " + incomingMessage.Body);
The Twilio documentation does not show it like this but I also have my SendSms ActionResult in the same controller, could that be my issue?
I had a bad url. The app was placed in a virtual directory called sms so the actual webhook should have benn
https://www.myUrl/admin/applicantmanagement/sms/Sms/ReceiveSms
http://www.asp.net/mvc/tutorials/mvc-4/using-oauth-providers-with-mvc
I'm using code from this tutorial (of course, not all). Everything works perfectly, but when I tried to pass email, I have System.Collections.Generic.KeyNotFoundException. Why? How can I pass e-mail value from Facebook?
return View("ExternalLoginConfirmation", new RegisterExternalLoginModel {
UserName = result.UserName,
ExternalLoginData = loginData,
FullName = result.ExtraData["name"],
Email = result.ExtraData["email"],
ProfileLink = result.ExtraData["link"],
});
This works:
return View("ExternalLoginConfirmation", new RegisterExternalLoginModel {
UserName = result.UserName,
ExternalLoginData = loginData,
FullName = result.ExtraData["name"],
//Email = result.ExtraData["email"],
ProfileLink = result.ExtraData["link"],
});
Regards
Facebook doesn't share Email addresses by default. See this post for more information, but you can change your registration model to require email when making a user registration for your site. Also, you can check that the collection has the key first, before trying to access it
AuthenticationResult result =
OAuthWebSecurity
.VerifyAuthentication(
Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
// Log in code
if (result.ExtraData.ContainsKey("email"))
// Use email
In my MVC4 application, I'm using the SmtpClient to send out email via Gmail's smtp.gmail.com SMTP server.
I've configured my Web.Config file with the following settings:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network enableSsl="true"
defaultCredentials="false"
host="smtp.gmail.com"
port="587"
userName="xxMyUserNamexx#gmail.com"
password="xxMyPasswordxx" />
</smtp>
</mailSettings>
</system.net>
The method that uses the SmtpClient and sends an email message looks like:
public void SendMail(string fromDisplayName, string fromEmailAddress, string toEmailAddress, string subject, string body)
{
MailAddress from = new MailAddress(fromEmailAddress, fromDisplayName);
MailAddress to = new MailAddress(toEmailAddress);
MailMessage mailMessage = new MailMessage(from, to);
mailMessage.Body = body;
mailMessage.Subject = subject;
SmtpClient client = new SmtpClient();
//client.UseDefaultCredentials = false;
client.Send(mailMessage);
}
The code above works as expected and is fine. What confuses me is the commented line client.UseDefaultCredentials = false; - If I were to uncomment that line, I'll receive an exception message that states:
The SMTP server requires a secure connection or the client was not
authenticated. The server response was: 5.5.1 Authentication Required.
What's more is, it doesn't matter if I set the UseDefaultCredentials property to true or false, I'll still receive the exception message. The only way for me to avoid the exception message is to remove the line altogether.
Is this behavior normal? Can you explain why I'm receiving the exception message?
So why would me explicitly setting the property to false throw an exception?
The reason for this is because the setter for UseDefaultCredentials sets the Credentials property to null if you set it to false, or it sets it to the CredentialCache.DefaultNetworkCredentials property if set to true. The DefaultNetworkCredentials property is defined by MSDN as:
The credentials returned by DefaultNetworkCredentials represents the authentication credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default network credentials are the user credentials of the logged-in user, or the user being impersonated.
When you set UseDefaultCredentials to true, it's using your IIS user, and I'm assuming that your IIS user does not have the same authentication credentials as your account for whatever SMTP server you're using. Setting UseDefaultCredentials to false null's out the credentials that are set. So either way you're getting that error.
Here's a look at the setter for UseDefaultCredentials using dotPeek:
set
{
if (this.InCall)
{
throw new InvalidOperationException(
SR.GetString("SmtpInvalidOperationDuringSend"));
}
this.transport.Credentials = value
? (ICredentialsByHost) CredentialCache.DefaultNetworkCredentials
: (ICredentialsByHost) null;
}
I was getting the same message and it was driving me crazy. After reading this thread I realized that the order mattered on setting my credentials. This worked:
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(smtpSettings.Username, smtpSettings.Password);
While this generated the error you describe:
client.Credentials = new NetworkCredential(smtpSettings.Username, smtpSettings.Password);
client.UseDefaultCredentials = false;
This is just an FYI to anybody else having the same problem.
This option will set the client to use the default credentials of the currently logged in user
If you set it to true, then it will try to use the user's credentials. If you set it to false, then it will use the values explicitly set for the Credentials property of the client, and if they aren't explicitly set, then it will try to connect anonymously as you are seeing.
This is how we can create SMTP Client with or without NetworkCredentials. I am using this code to send emails. We should use client.UseDefaultCredentials only when we are not passing credentials and going by default.
private SmtpClient InitializeSMTPClient()
{
var client = new SmtpClient(_smtpServer, _smtpPort);
client.UseDefaultCredentials = _useSMTPDefaultCredentials;
if (_useSMTPDefaultCredentials)
return client;
var credentials = new NetworkCredential(_smtpUsername, _smtpPassword);
client.Credentials = credentials;
return client;
}
SMTPEmailResult SendSMTPEmail(List<string> to_email, List<string> ccEmails, string subject, string message)
{
try
{
using (var client = InitializeSMTPClient())
{
var mail_message = GetMailMessage(to_email, ccEmails, subject, message);
log.Debug("Sending SMTP email.");
client.Send(mail_message);
log.Debug("SMTP email sent successfully.");
return SMTPEmailResult.SendSuccess;
}
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
return SMTPEmailResult.SendFailed;
}
}
I have mvc web app sending an email when new user gets created with following code:
private static void SendMail(User user)
{
string ActivationLink = "http://localhost/Account/Activate/" +
user.UserName + "/" + user.NewEmailKey;
var message = new MailMessage("ashu#gmail.com", user.Email)
{
Subject = "Activate your account",
Body = ActivationLink
};
var client = new SmtpClient("localhost");
client.UseDefaultCredentials = false;
client.Send(message);
}
What's wrong with my code please tell me.
ERROR : Failure sending mail. {"Unable to connect to the remote server"}
Smtp configuration :
Here are the likely causes of this error:
1 You are not supplying the correct authentication details
2 The port is blocked, for example by a firewall
In your example, I notice you are not specifying the port when you create your SmtpClient - it may help to specify it.
Gmail opens in port 587, and u need to enable ssl.
Try following code.
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(<fromAddress>, <fromPassword>)
};
using (var message = new MailMessage(<fromAddress>, <toAddress>)
{
Subject = <subject>,
Body = <body>
})
{
smtp.Send(message);
}
From my WSDL I have the following service part:
<service name="BAPI_CUSTOMER_DISPLAYService">
<documentation>SAP Service BAPI_CUSTOMER_DISPLAY via SOAP</documentation>
<port name="BAPI_CUSTOMER_DISPLAYPortType" binding="s0:BAPI_CUSTOMER_DISPLAYBinding">
<soap:address location="http://2.3.4.100:8000/sap/bc/soap/rfc"/>
</port>
</service>
then what will be endpoint reference for this?
I am giving it as "http://2.3.4.100:8000/sap/bc/soap/rfc" in my salesforce client and it gives the following error.
"This service requires client certificate for authentication procedure."
I am sure that i need to give user name and password not knowing how i can set them in my client which is a Apex code.
Help is appreciated.
I imported the Enterprise WSDL and used the uri from the loginResult. Here's some code from my project:
LoginResult loginResult = null; // Login Result (save and make static)
SessionHeader sessionHeader = null; // Session Header (save and make static)
SoapClient soapClient = null; // This is the Enterprise WSDL
SecureStatusClient SecureStatusClient = null; // This is my custom #WebService
// Create Login Request
LoginScopeHeader loginScopeHeader = new LoginScopeHeader
{
organizationId = configuration["OrganizationId"],
portalId = configuration["PortalId"]
};
// Call Login Service
string userName = configuration["UserName"];
string password = configuration["Password"];
string securityToken = configuration["SecurityToken"];
using (SoapClient loginClient = new SoapClient())
{
loginResult = loginClient.login(loginScopeHeader, userName, password + securityToken);
if (result.passwordExpired)
{
string message = string.Format("Salesforce.com password expired for user {0}", userName);
throw new Exception(message);
}
}
// Create the SessionHeader
sessionHeader = new SessionHeader { sessionId = loginResult.sessionId };
// Create the SoapClient to use for queries/updates
soapClient = new SoapClient();
soapClient.Endpoint.Address = new EndpointAddress(loginResult.serverUrl);
// Create the SecureStatusServiceClient
secureStatusClient = new SecureStatusServiceClient();
Uri apexUri = new Uri(SoapClient.Endpoint.Address.Uri, "/services/Soap/class/SecureStatusService");
secureStatusClient.Endpoint.Address = new EndpointAddress(apexUri);