0

I just created method to send an confirmation mail when new user register

this is the controller

if (result.Succeeded)
    {
        var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("AFFEMS2-HEC");
        UserManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<ApplicationUser>(provider.Create("EmailConfirmation"));


        var currentUser = UserManager.FindByName(user.UserName);

        var roleresult = UserManager.AddToRole(currentUser.Id, model.RoleName);




        System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
            new System.Net.Mail.MailAddress("my@email.lk", "Registration System "),
            new System.Net.Mail.MailAddress(user.Email));
        m.Subject = "Account Activation";


        m.Body = string.Format("Dear {0},<BR/><BR/>Your account has been successfully created with the Higher Education Council. Please click on the link below to access your account. : <a href=\"{1}\" title=\"User Email Confirm\">{1}</a>", user.UserName, Url.Action("ConfirmEmail", "Account", new { Token = user.Id, Email = user.Email }, Request.Url.Scheme));



        m.IsBodyHtml = true;
        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("##.##.##.###");
        smtp.Port = ##;
        smtp.Credentials = new System.Net.NetworkCredential("my@email.lk", "#######");
        smtp.EnableSsl = false;
        smtp.Send(m);


        this.SetNotification("The User has been successfully registered. A confirmation Email has been sent to: " + user.Email, NotificationEnumeration.Success);
        return RedirectToAction("View_Users", "Account");
    }

Now I want

1.Attach image in to email body(above the email body)

2.Shrink the activation link (without sending large link its should contain small piece of text) of this confirmation message.

How can I achieve those things ?

Shehary
  • 9,926
  • 10
  • 42
  • 71
Chathz
  • 723
  • 4
  • 16
  • 41

1 Answers1

0

1.Attach image in to email body(above the email body)

Since you are using the System.Net.Mail namespace you so should be able to take advantage of the Attachment class. Alternatively you could host an image on a server and add an image tag to your MailMessage.Body which points to that file.

<img src="my-image.jpg" />

2.Shrink the activation link (without sending large link its should contain small piece of text) of this confirmation message.

If you really want to shrink the code then you would need to create your own implementation of the IUserTokenProvider interface. Here you can define your own method of creating and verifying a token or code.

heymega
  • 9,215
  • 8
  • 42
  • 61