【问题标题】:Add image and shrink the activation link of confirmation email in aspnet identity在 aspnet 身份中添加图像并缩小确认电子邮件的激活链接
【发布时间】:2015-08-23 23:59:42
【问题描述】:

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

这是控制器

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.收缩此确认消息的激活链接(不发送大链接,应包含小段文字)。

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

【问题讨论】:

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


    【解决方案1】:

    1.将图片附加到邮件正文中(邮件正文上方)

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-16
      • 2015-08-17
      • 2013-03-06
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2011-02-14
      • 2014-06-11
      相关资源
      最近更新 更多