-1

I am creating an android application using Xamarin on Visual Studio 2017. I am trying to run an automated email feature that sends emails when a user registers an account with my application. I am using the NuGet package MailKit for this.

var mailSender = new MailboxAddress("useremail@gmail.com");

When I use this code, it creates the MailboxAddress perfectly fine and I can send an email to the address I have specified without any errors. However when I use this code:

string email = getEmail.Text;
var mailSender = new MailboxAddress(email);

I am going into break mode with an unhandled exception. The variable email definitely has a value in it which I have inspected whilst debugging.

Any idea as to why it wouldn't let me create this object using a variable instead of a hard coded string?

Thanks

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
broliverparker
  • 217
  • 2
  • 15

1 Answers1

2

The MailboxAddress .ctor that takes only a single string is meant to only accept "user@domain"-style addresses. If you plan to pass in user-entered text, then you need to use MailboxAddress.Parse()

jstedfast
  • 35,744
  • 5
  • 97
  • 110