C# Webmail.Send method how to change person name - c#

WebMail.SmtpServer = SmtpServer;
WebMail.UserName = SmtpUsername;
WebMail.Password = SmtpPassword;
WebMail.Send(
ReplayEmail,
subject,
body,
email
);
subject is for example "Ask specialist"
body is html body
email is for example "domain#domain.com"
email is send to for example "domain2#domain.com"
now when i send mail i get mail which is ok but as person who send mail I see "domain2#domain.com". how to change this?
mail now looks like
domain2#domain.com Ask specialist
i want name (Adoo for example) and mail like
Adoo Ask specialist

If I understand correctly, when setting up mail you can do :
mail.To = new MailAddress("domain2#domain.com", "Adoo");
or :
mail.To= #"\Adoo \ <domain2#domain.com>";

I'm assuming ReplayAddress is a System.Net.Mail.MailAddress defined in code somewhere else you haven't shown. MailAddress has a constructor which takes a string displayName which should do what you want if I understand you correctly - documentation on that is here.

Typically in SMTP you can create a friendly name by using a format like this:
WebMail.Send(
"\"Adoo\" <domain2#domain.com>",
subject,
body,
email
);

or you can use
mail.To= #""Adoo" <domain2#domain.com&gt";

You are using the WebMail class which takes a string for the .From property of the class. I would use the MailAddress class and do:
MailAddress from = new MailAddress("domain2#domain.com", "Adoo Ask specialist");

Related

c# Send Email using Process.Start

I want to send simple email with no attachment using default email application.
I know it can be done using Process.Start, but I cannot get it to work. Here is what I have so far:
string mailto = string.Format("mailto:{0}?Subject={1}&Body={2}", "to#user.com", "Subject of message", "This is a body of a message");
System.Diagnostics.Process.Start(mailto);
But it simply opens Outlook message with pre-written text. I want to directly send this without having user to manually click "Send" button. What am I missing?
Thank you
You need to do this :
string mailto = string.Format("mailto:{0}?Subject={1}&Body={2}", "to#user.com", "Subject of message", "This is a body of a message");
mailto = Uri.EscapeUriString(mailto);
System.Diagnostics.Process.Start(mailto);
I'm not sure about Process.Start() this will probably always only open a mail message in the default Mail-App and not send it automatically.
But there may be two alternatives:
Send directly via SmtpClient Class
using Outlook.Interop
You need to do this:
SmtpClient m_objSmtpServer = new SmtpClient();
MailMessage objMail = new MailMessage();
m_objSmtpServer.Host = "YOURHOSTNAME";
m_objSmtpServer.Port = YOUR PORT NOS;
objMail.From = new MailAddress(fromaddress);
objMail.To.Add("TOADDRESS");
objMail.Subject = subject;
objMail.Body = description;
m_objSmtpServer.Send(objMail);

Add a different 'reply to' Email address in MailDefinition C#

I am using Windows Form Application which is sending HTML emails using MailDefinition Class.
MailDefinition mailDefinition = new MailDefinition();
mailDefinition.BodyFileName = strfilename;
mailDefinition.From = "email#company.com";
Is it possible that somehow I can add a different email id where user will reply. I don't want the users to reply on this email#company.com email id.
I am looking for some thing like this:
mail.Headers.Add( "Reply-To", "alternate_email#mycompany.com")
I use the System.Net.Mail.SmtpClient class which has a send method that takes a System.Net.Mail.MailMessage parameter.
In the MailMessage class it has: replyTo and replyToList properties.
Add HTML content like this:
System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage();
m.Body = "HTML Content";
m.IsBodyHtml = true;

MailMessage setting the Sender Name EWS

I want to send email with EWS using custom display name.
Here is my Code:
EmailMessage message = new EmailMessage();
message.From = new EmailAddress("someone","one#two.com");
My expectation is that the received email to come from: someone <one#two.com>
Instead of this I get the email from: one <one#two.com>
Anybody know what would be the problem here?
EDIT
Have you tried this?
new EmailAddress("someone <one#two.com>;");
PREVIOUS
System.Net.Mail Namespace has MailAddress class, not EmailAddress.
Are you using System.Net.Mail? And if not why not?
MailAddress Constructor (String, String) is this:
public MailAddress(
string address,
string displayName
)
so you should use this way:
message.From = new MailAddress("one#two.com","someone");

How can I use a variable to define MailAddress toAddress in c#?

I have an ASP.NET 4.0 aspx page from which I wish to send an email to the recipient specified in a text box named "supervisoremailTextBox". Is there any way that I can specify a variable as the recipient email address. The code I have used which doesn't work is shown below:
MailAddress fromAddress = new MailAddress("address#domain.co.uk", "Sender Name");
MailAddress toAddress = new MailAddress("supervisoremailTextBox.Value");
message.From = fromAddress;
message.To.Add(toAddress);
Sorry if this a really dumb question and thanks in advance for your help.
When you use MailAddress, you need to use a valid email address.
The string "supervisoremailTextBox.Value" is not a valid email address.
If you mean to use the value of a textbox with the ID supervisoremailTextBox, use:
MailAddress toAddress = new MailAddress(supervisoremailTextBox.Value);
Note that I have dropped the " to ensure you are not passing in a string.
Try this instead:
MailAddress toAddress = new MailAddress(supervisoremailTextBox.Value);

subject line of email message

I'm writing an asp.net mvc app. in c#, and I'm wondering if anybody can help me to understand, if it's possible to include an input from another field stored in the database, like a numeric or text string into a subject line of the email.
For example, along with the subject text, like "Your event registration" I'd like to add a "registartion ID" into a subject line of my email.
Right now i have a code in my emailhepler.cs:
public static void NotifyHtml(string toAddress, string subject, string body)
{
MailMessage message = new MailMessage();
message.To.Add(toAddress);
message.From = new MailAddress("coe-RoomReservations#coe.berkeley.edu");
message.Subject = subject;
Yes. When you call your method, you should be able to format your subject however you want. E.g.,
NotifyHtml("coe-RoomReservations#coe.berkeley.edu", string.format("#{0} Your event registration", registrationId), body);
message.Subject = String.Format("{0} : {1}", subject, registrationID);
Yes. Hope I didn't misunderstand your question. MailMessage.Subject is just a property of type String so you can include anything that's formatted as a string.
message.Subject = string.Format("Your event registration; registration id : {0}", registrationId);

Categories

Resources