question

RobertGustafson-1682 avatar image
0 Votes"
RobertGustafson-1682 asked RobertGustafson-1682 edited

Is it possible, using Mailkit's SmtpClient, to create an app that lets the end user email someone else?

WHAT I HAVE:
Visual Basic 2019, .NET 4.6.1, WinForms, Mailkit

MY ISSUE:
I've figured out how to configure my desktop app to send someone an email from me (from the app). (Since the server is "smtp.aol.com", I had to create an "app password" for the credentials.)

What if I want my app to enable the end user to send an email to someone from himself/herself? Is that possible? So far, when I set the message.From list to only other people's email addresses or set message.Sender to someone else's than mine, I get a "Mailbox Unavailable" error. (And when the "From" list includes me and the "Sender" is me, the email is sent, but I am identified on it as the sole 1 sending it.) (I'm using my own [my app's] SMTP address and user-name/password credentials for authentication. Show those things be instead of the one who's "supposedly" doing the sending in order for the app to send the email "from him/her"? If so, and their SMTP is "smtp.aol.com", should the password be theirs [which they'd supply] or the "app password" I referred to earlier?)

I need to be able to set up my desktop app so that people can use it to send basic emails to one another. (That, and internet access general, is a minor part of the overall app, but I'd like to include it, because it's a contact-list program that stores info about people/organizations, including email addresses, and it'd be a pity if those addresses can't be used except through a separate program/browser, where none of my app's features apply.)

I'm guessing tentatively that I should configure my app to let the user determine the SMTP address (for Connect) and enter his/her credentials (for Authenticate) before my app sends his/her email. Is this the best solution (for a desktop app, anyway)? My only concern, after reading around the net about this, is what the password should be if they're using "smtp.aol.com"--their password or the "app password"?

I'd ask AOL, but it's the middle of the night, and their chat lines are closed right now.














dotnet-visual-basicwindows-forms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered RobertGustafson-1682 edited

I'd create a class that contains data to allow a user to send an email. In the code sample I did just enough to see if this would work for you. add a form to enter data for editing plus any validation you want.

Example 1 works with app.config, stores data in user.config while example 2 works with a json file. Both encrypt/decrypt data.

 {
   "UserName": "AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAeyGgHNEX6UeW1fJWdfqQbgAAAAACAAAAAAADZgAAwAAAABAAAADE+2HrEB+FxKBavWYqCqYhAAAAAASAAACgAAAAEAAAAPDLmEW3NYC/xO3N/Wj5XpgQAAAAq8DaWpFFvhFuKswKuaMDKxQAAABr8AyT0sbsw9vaBipgtpVPP9mnug==",
   "UserPassword": "AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAeyGgHNEX6UeW1fJWdfqQbgAAAAACAAAAAAADZgAAwAAAABAAAADkMR+W6HYYNSISdxKbyV7gAAAAAASAAACgAAAAEAAAAMq7LPuGsnsiq7Rbi1KaZB4YAAAAOoxjALdhYocdhCvqV4BO2jzVEn/SiTwIFAAAAI4KcHcFhacHoQZtv90IAFBNQ7NQ",
   "UseDefaultCredentials": false
 }


Or

 <?xml version="1.0" encoding="utf-8"?>
 <configuration>
     <userSettings>
         <EncryptSettings.My.MySettings>
             <setting name="UserName" serializeAs="String">
                 <value>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAeyGgHNEX6UeW1fJWdfqQbgAAAAACAAAAAAADZgAAwAAAABAAAABZFC4XA/X8wjGciCFs/ZrrAAAAAASAAACgAAAAEAAAAJcw4MWAdi4DzluIZ1zVhVsQAAAA4Uv2uISf/V+FHI9xjWobGRQAAABPipwy+z89Ke3WM9ohlfGQGogZdw==</value>
             </setting>
             <setting name="UserPassword" serializeAs="String">
                 <value>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAeyGgHNEX6UeW1fJWdfqQbgAAAAACAAAAAAADZgAAwAAAABAAAABC5iAejR5qnLmgl1ArNIhYAAAAAASAAACgAAAAEAAAAFyO424vTqpo2RQpNm3bKaEYAAAA2ZR5rfz7lpEPD+kCeE2bgy1ycxeAzniQFAAAAKh4FJtpAyUJcr3Z0rbg3ikiJz6C</value>
             </setting>
         </EncryptSettings.My.MySettings>
     </userSettings>
 </configuration>


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I want a programmatic VB-code-driven answer (not an XML one). I want my app to allow the end user to specify their server and credentials (user-name/password) using a dialog box, and then send an email to someone so that the email is seen by their recipient as coming from their email address, not mine or the app's. Can it be done, provided he/she is doing it from one's own machine? (I can't seem to "simulate" it from mine--which is maybe a good thing, but makes code hard to test.)

I'm guessing that the From collection and/or Sender property needs to contain their address, and their address and password have to be used in the Authenticate method (after their server is plugged in in the Connect method), although I can't test that from my side because I don't have access to another's account. Am I right about what needs to be done? Are there any code considerations to take into account that I haven't mentioned?








0 Votes 0 ·

The idea I provided as mentioned has just enough to show a concept.

I want my app to allow the end user to specify the server and credentials (user-name/password) using a dialog box. Then when sending an email retrieve details from the json file or user.config file.

Exactly what I was suggesting, create a dialog, have controls to allow a user to enter server, credentials, user-name and password and anything else needed encrypted. Personally I never use My.Setting, always use json for desktop and web solutions.

Regarding testing, perhaps setup a gmail account for testing as you should be testing as this is a popular email provider.

0 Votes 0 ·

But when and end user installs my app on his/her machine, their server/user-name/password will work with the program written as I've suggest, provided he/she has access to their account even though I don't? That is, the end user won't have to send from an account I or my app has access to, right?!


0 Votes 0 ·