Click or drag to resize

EmailFactoryNewEmail Method

Create a new empty instance of email

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public static IEmail NewEmail(
	IContext context
)

Parameters

context
Type: AskiaPortalCmnIContext
Context of execution

Return Value

Type: IEmail
Return a new empty email or null if the user in the context doesn't have enough right to create an email
Examples

Create a new email and save it

var context = ContextFactory.CreateByUserGuid(Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D"));   
var contextValidation = context.Validate();
if (!contextValidation.Success)
{
    throw contextValidation.Exception;
}
const int english = 1;
var email = EmailFactory.NewEmail(context);
var emailMessage = email.Translations.FindOrCreate(english);         
emailMessage.Subject = "Welcome!";
emailMessage.Body = "Hello world!";
if (email == null)
{
    Console.Error.WriteLine("Could not create a new email");
    return;
}
email.Name = "My new email";
var saveResult = email.Save();
if (saveResult.Success)
{
    Console.WriteLine("The email `{0}` (Id={1}) was successfully saved",
                                    email.Name, email.Id);
}
else
{
    Console.Error.Write(saveResult.Exception.Message);
}
See Also