1

This is the settings:

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"

I am getting this exception:

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

Update

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);
    }
}
aaron
  • 39,695
  • 6
  • 46
  • 102
Nighil
  • 4,099
  • 7
  • 30
  • 56

2 Answers2

3

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

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.

Contact the system administrator of your SMTP server.

using smtp ordinary .net code it is working fine

You can send a MailMessage using IEmailSender too.

aaron
  • 39,695
  • 6
  • 46
  • 102
0

This has nothing to do with aspnetboilerplate. as the error says "This mail server requires authentication when attempting to send to a non-local e-mail address. "

Possible causes:

  • Email client is not configured for SMTP authentication and the server is
  • Firewall or email proxy software is preventing SMTP authentication from occurring
  • Email client has incorrect credentials configured or does not match server settings.

What you can do is download the application below to test your smtp settings. http://www.alexnolan.net/software/SMTPProber.htm

Once you send email successfully, use the correct settings in aspnetboilerplate.

Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55