c# - Send Email from Alias Address using SMTP -
this question has been asked many times still struggling find working solution.
please consider below code:
smtpclient mailclient = new smtpclient("outlook.office365.com"); mailmessage msgmail = new mailmessage(); msgmail.from = new mailaddress("validuser@domain.com", "displayname@aliasdomain.com"); mailclient.usedefaultcredentials = false; mailclient.credentials = new networkcredential("validuser@domain.com", "password"); mailclient.enablessl = true; mailaddress sendmailto = new mailaddress("somevaliduser@somevaliddomain.com", "mark twain") msgmail.to.add(sendmailto); msgmail.subject = "test subject"; msgmail.body = "email content"; msgmail.isbodyhtml = true; mailclient.send(msgmail); msgmail.dispose();
when somevaliduser
- recipient - receives email, want show display name : displayname@aliasdomain.com
opposed username registered validuser@domain.com
account.
how can achieve this?
try adding display name headers of message:
msgmail.headers.add("sender", "displayname@aliasdomain.com");
i hope helps.
Comments
Post a Comment