在aspnet标识中添加图像并缩小确认电子邮件的激活链接

时间:2015-04-10 06:47:30

标签: asp.net asp.net-mvc asp.net-mvc-4 asp.net-identity confirmation-email

我刚创建了在新用户注册时发送确认邮件的方法

这是控制器

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");
    }

现在我想要

1.将图像附加到电子邮件正文(电子邮件正文上方)

2.收缩此确认消息的激活链接(不发送包含小段文本的大链接)。

我怎样才能实现这些目标?

1 个答案:

答案 0 :(得分:0)

  

1.将图像附加到电子邮件正文(电子邮件正文上方)

由于您使用的是System.Net.Mail命名空间,因此您应该能够利用Attachment class.。或者您可以在服务器上托管图像并向MailMessage.Body添加图像标记它指向该文件。

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

2.收缩此确认消息的激活链接(不发送包含小段文本的大链接)。

如果您真的想缩小代码,那么您需要创建自己的IUserTokenProvider接口实现。在这里,您可以定义自己创建和验证令牌或代码的方法。