在aspnetboilerplate中发送的电子邮件不起作用 [英] Email sending in aspnetboilerplate not working

查看:176
本文介绍了在aspnetboilerplate中发送的电子邮件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是设置:

AddSettingIfNotExists(EmailSettingNames.DefaultFromAddress, "abc@xyz.tech");
AddSettingIfNotExists(EmailSettingNames.DefaultFromDisplayName, "abc.tech Emailservice");
AddSettingIfNotExists(EmailSettingNames.Smtp.UserName, "abc@xyz.tech");
AddSettingIfNotExists(EmailSettingNames.Smtp.Domain, "abc.tech");
AddSettingIfNotExists(EmailSettingNames.Smtp.EnableSsl,"false");
AddSettingIfNotExists(EmailSettingNames.Smtp.Host, "webmail.abc.tech");
AddSettingIfNotExists(EmailSettingNames.Smtp.Port, "25");
AddSettingIfNotExists(EmailSettingNames.Smtp.Password, "gdfdgd");
AddSettingIfNotExists(EmailSettingNames.Smtp.UseDefaultCredentials, "false");

这是电子邮件发送代码:

This is the email sending code:

// See "Update"

我遇到此异常:

命令序列错误.服务器响应为:此邮件服务器 尝试发送到非本地电子邮件时需要身份验证 地址.请检查您的邮件客户端设置或与您的 管理员以验证为此定义了域或地址 服务器

Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server

更新

public class UserAppService // ...
{
    private readonly UserManager _userManager;
    private readonly RoleManager _roleManager;
    IRepository<User, long> _rep;
    private readonly IRepository<Role> _roleRepository;
    private readonly IPasswordHasher<User> _passwordHasher;
    public readonly IEmailSender _emailSender;

    public UserAppService(
        IRepository<User, long> repository,
        UserManager userManager,
        RoleManager roleManager,
        IRepository<Role> roleRepository,
        IPasswordHasher<User> passwordHasher, IEmailSender em)
        : base(repository)
    {
        _rep = repository;
        _userManager = userManager;
        _roleManager = roleManager;
        _roleRepository = roleRepository;
        _passwordHasher = passwordHasher;
        _emailSender = em;
    }

    [AbpAllowAnonymous]
    public override async Task<UserDto> Create(CreateUserDto input)
    {
        // CheckCreatePermission();

        var user = ObjectMapper.Map<User>(input);

        user.TenantId = AbpSession.TenantId;
        user.Password = _passwordHasher.HashPassword(user, input.Password);
        user.IsEmailConfirmed = false;

        CheckErrors(await _userManager.CreateAsync(user));

        if (input.RoleNames != null)
        {
            CheckErrors(await _userManager.SetRoles(user, input.RoleNames));
        }

        CurrentUnitOfWork.SaveChanges();

        try
        {
            await _emailSender.SendAsync("test@gmail.com", "sdfs", "sdfsd", false);
        }
        catch (Exception ex)
        {
        }

        return MapToEntityDto(user);
    }
}

推荐答案

尝试发送到非本地电子邮件地址时,此邮件服务器需要身份验证.

This mail server requires authentication when attempting to send to a non-local e-mail address.

看起来像您的SMTP服务器有问题(相关).

Looks like an issue with your SMTP server (related).

尝试向自己或同一域中的其他用户发送电子邮件.

Try sending an email to yourself or another user in the same domain.

我无法将邮件发送到正在工作的同一域的其他域.

I can't send mail to other domains same domain it is working what will be the problem.

与SMTP服务器的系统管理员联系.

Contact the system administrator of your SMTP server.

使用smtp普通.net代码可以正常工作

using smtp ordinary .net code it is working fine

您也可以使用IEmailSender发送MailMessage.

这篇关于在aspnetboilerplate中发送的电子邮件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆